Emulation of a Z80 CP/M computer on an Arduino DUE

Similar projects worth following
(Attention: this project has been merged onto my RunCPM project, also featured here)

Wrote an emulation of a Z80 computer running CP/M inside an Arduino DUE.
This is modeled after an emulation I wrote for Windows, which allows to run old CP/M 2.2 applications on modern windows operating systems.
It can be easily ported to other operating systems, so I ported it to the Arduino platform.
The Arduino required is the DUE, due (no pun intended) to the amount of memory it has, which is needed to contain the 64K RAM for the CP/M CPU.

The sourcecode for the emulator and the original one for windows are to be found at: - For the Arduino version. - For the Windows version.

Please feel free to try it, break it, fix it and improve it. Just let me know how you lik

Instead of using CP/M disk images, which can be cumbersome and complicated to manage, this project uses a regular FAT filesystem, and emulates CP/M disk drives as subfolders to the SD card, so folder "A" will be disk A:, folder "B" will be disk B: and so on, up to disk P: (the max supported by CP/M).

The emulations acts like a framework on top of the disk system, making the emulated Z80 CPU "think" it has a real CP/M disk environment available.

Some of the physical disk related calls (like moving a disk drive head) are not available, for obvious reasons.

So far I have tried Wordstar, Microsoft Basic, Turbo Pascal, dBase II, UCD Micromumps and more. Everything worked fine, so I guess the emulation if pretty solid.

My special thanks goes to a guy from California called Tom Burnett, for being an "early adopter" and providing a second set of eyes by doing a lot of debugging/testing.

  • 1 × Arduino DUE
  • 1 × SD Card shield
  • 30 × Sleepless nights

View project log

Enjoy this project?



moxhamj wrote a day ago point

Brilliant project. Working right out of the box. I used Putty for a terminal as this can handle the VT100 codes that Wordstar uses. Also bumped the baud rate up to 115200. Having used emulations in the past that needed CP/M disk images, this is *much* easier with your system of putting files in fat32 directories. Must have been a lot of work behind the scenes getting that working! Next step - building a terminal using one of the cheap TFT touchscreens. Cheers, James Moxham

  Are you sure? yes | no

Martian wrote 01/23/2017 at 21:36 point

  Are you sure? yes | no

Martian wrote 01/23/2017 at 14:19 point

I'll write it up as a project and send you a link ;-)

  Are you sure? yes | no

Marcelo Dantas wrote 01/23/2017 at 14:05 point

Awesome news!!! .... have pictures??? ... share your experience. I keep thinking about building a hardware version myself ... just too lazy.

  Are you sure? yes | no

Martian wrote 01/23/2017 at 09:04 point

Just a quick update, I finished building my CP/M computer, it's nicely cased etc.  Got the drive full of software and I have been using it a lot, thanks again for this project and helping me build my own CP/M computer!

  Are you sure? yes | no

Marcelo Dantas wrote 07/29/2016 at 00:22 point

Hi All,

Now the Arduino DUE version has access to the Arduino DUE pins via BDOS calls.

So you can write CP/M programs in any language capable to run BDOS calls, and access the Arduino DUE pins with them.

The Arduino DUE call framework was written by a good friend, Kzysztof Klis.

Have fun,


  Are you sure? yes | no

Martian wrote 06/09/2016 at 21:49 point

Thanks for the prompt reply, great project you have there.  I think I'll acquire a Due, I'd love my own little CP/M computer.  I'll let you know how I get on.  :)

  Are you sure? yes | no

Martian wrote 06/09/2016 at 19:43 point

Where does this project stand as of June 2016?  If I buy a Due and download the source, can I build a reliable CP/M system with it?

Also I have a SPI MicroSD adaptor from another project I've been working on, would that work as is?


  Are you sure? yes | no

Marcelo Dantas wrote 06/09/2016 at 20:16 point

I have it running on a Due with a micro SD shield ... the code is fully function and emulates a CP/M machine nicely.

  Are you sure? yes | no

Marcelo Dantas wrote 06/09/2016 at 20:17 point

Regarding the SPI MicroSD, as long as you use the same FAT library (see posts below) then you should have no problems. But it is still a hit/miss ... I can't make guarantees on your adapter, unfortunately.

  Are you sure? yes | no

Martian wrote 12/24/2016 at 21:39 point

Just an update, I've treated myself to a DUE clone and have used the SPI MicroSD adaptor, works fantastically.  Boots CP/M, can run MBASIC programs.  I'm having problems locating working software like WordStar etc.  Most places I find that have VT-100 friendly software seem to be in .DSK files and I can't mount those or extract the apps from them.  Any ideas?  Or do you know of a better archive?

  Are you sure? yes | no

CRISTIAN wrote 11/30/2015 at 00:58 point

Thank you, you're very kind, try to implement the code in a Arduino Mega.

  Are you sure? yes | no

CRISTIAN wrote 11/27/2015 at 22:44 point

Tkanks for you atencion!.

I managed refedinir the ROMSIZE , but ahun no conflict with the int32 SP ; tells me that :

sketch\cpu.h:11:7: error: expected ')' before 'volatile'.

Perhaps the int SP, has a conflict .
What could I do?

  Are you sure? yes | no

Marcelo Dantas wrote 11/28/2015 at 13:59 point

Hello Christian,

The ATmega328 has only 32K bytes of Flash, while the compiled code of CPMDuino has 57K, so it will not fit.

I am quite sure that you are having these errors because of this incompatibility.

Your only option would be to use an Arduino DUE.

The Arduino DUE has 96K of RAM and 512K of flash (see the differences here:

In fact, I chose the Arduino DUE to migrate my Windows based code exactly because it had lots of memory (RAM and Flash).

CPMDuino is a very big code, it needs lots of memory and CPU power to run.

Feel free to send me an email on marcelo[dot]f[dot]dantas[at]gmail[dot]com if you want to discuss other options.



  Are you sure? yes | no

CRISTIAN wrote 11/26/2015 at 23:28 point

Arduino:1.6.6 Hourly Build 2015/07/20 04:41 (Windows 8.1), Placa:"Arduino Nano, ATmega328"
In file included from CPMduino.ino:12:0:
sketch\abstraction_arduino.h:18:18: error: size of array 'RAM' is negative
 uint8 RAM[RAMSIZE]; // RAM must go into memory
In file included from c:\users\fmv\downloads\arduino\arduino-nightly\hardware\tools\avr\avr\include\avr\io.h:99:0,
                 from c:\users\fmv\downloads\arduino\arduino-nightly\hardware\tools\avr\avr\include\avr\pgmspace.h:88,
                 from C:\Users\FMV\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.8\cores\arduino/Arduino.h:28,
                 from C:\Users\FMV\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.8\libraries\SPI/SPI.h:17,
                 from CPMduino.ino:3:
sketch\cpu.h:11:7: error: expected unqualified-id before 'volatile'
 int32 SP;  /* SP register                                  */
sketch\cpu.h:11:7: error: expected ')' before 'volatile'
sketch\cpu.h:11:7: error: expected ')' before 'volatile'
Error de compilación
  This report would have more information with
  "Show verbose output during compilation"
  activala desde Archivo > Preferencias

  Are you sure? yes | no

Marcelo Dantas wrote 11/27/2015 at 13:23 point

Hi Cristian,

The CPMDuino code is specific for the Arduino DUE, because the CP/M machines had usually 64K of RAM, so only the Arduino DUE (as far as I know) is able to run it.

Maybe the other Arduinos would be able to do it by adapting the RAM abstraction functions inside abstraction.h, and by adding extra external RAM onto the board. 

However this would be a bit more complicated than I wanted to (and would add extra devices to the board) so I decided not to go that way.

I am not sure also if the UNO would be up to the task of running the emulation, as the DUE has a pretty powerful ARM processor.

Grande abraço,


  Are you sure? yes | no

CRISTIAN wrote 11/26/2015 at 23:28 point

Greetings, I congratulate you on your project , it is very Become interested , the reason for my question is whether the porgrama runs on Arduino one or nano, and another question is to know what is the mistake that keeps compile. I get:

  Are you sure? yes | no

Mark Bramwell wrote 11/22/2015 at 16:56 point

I am making great progress with the ESP8266 telnet server.  My question to you is:  What ESP8266 modules do you have?  I went nuts on ebay a few weeks ago and purchased a pair of every type I could find.  My favorite for development work is the nodemcu because it is the ESP8266 + power supply + USB chip all on a single board.  It makes it very easy to use and is breadboard friendly.

How do you expect to hook up one of these to your DUE? The 3.3v power requirements is higher than what is normally on an arduino output. The nodemcu will take raw 5v in and has its own regulator. I am thinking hooking into the DUE's raw power output pin and let the ESP board regulate it.

  Are you sure? yes | no

Marcelo Dantas wrote 11/23/2015 at 04:06 point

I ended up buying the modules without a breakout board of any type (they looked bigger in the picture)... so I had to order breakout boards on eBay, which are going to arrive at any moment.

Then I will decide how to do it. But this is subject for a new project. Let's not clutter here, drop me a note at marcelo[dot]f[dot]dantas[at]gmail[dot]com.



  Are you sure? yes | no

yeti wrote 11/21/2015 at 04:47 point

Can you please make versioned archives for download instead of presenting all source files individually? Or what about gitlab or something competitive?

  Are you sure? yes | no

Marcelo Dantas wrote 11/21/2015 at 13:57 point

Hi Yeti,

When I wrote CPMDuino I had no experience whatsoever with Github. Sorry.

The version at sourceforge is the latest, I uploaded it only when I considered the software to be finished. I am not developing it anymore.

I may move it into Github in the future, but being it so small (9 files only) and stale (no new versions for a while) I see no point on doing it right now.



  Are you sure? yes | no

Mark Bramwell wrote 11/20/2015 at 21:59 point

Success!   It compiles (no errors or warnings).  I'll document the steps on my site, I am sure google will find it if others start looking.  I want to add telnet support via an ESP8266.  Give me a week or two and I'll post my progress.

Thanks for help me through this all!

  Are you sure? yes | no

Marcelo Dantas wrote 11/20/2015 at 22:39 point

Cool ... that's good news.

I just got a couple ESP8266 modules myself for another project.

If you manage to make it work with the ESP8266 please let me know. I would like to give it a try too.


  Are you sure? yes | no

Mark Bramwell wrote 11/20/2015 at 19:06 point
ok, finding that library in your

c:\users\...\documents folder makes sense.

I am trying to make my environment match yours. 

I now get this error: " abstraction_arduino.h:189: error: 'class SdFile' has no member named 'getFilename'    dir.getFilename((char*)dirname);

I have manually done a search.  "getFilename" does not exist in any of the sd or sdfat libraries.  It only exists in your abstraction_arduino.h   (and is being called by your code but the actual code is not in there)

The sourceforge link in your blog has 9 files.  Can you confirm that 9 files are the required amount?  One of your messages mentions CPM22.BIN which is not in that 9-file listing but I found it in the windows version.  Do I need more source files (other than the 9 CPMduino files) ?

  Are you sure? yes | no

Marcelo Dantas wrote 11/20/2015 at 20:37 point

Yup ... only those 9 files.

The "getFilename" comes from "dir", which is instantiated on line 6 of CPMduino.ino from SdFile.

SdFile.cpp somehow is on my SdFat library, and googling for that sent me to a SdFat created by SparkFun.

It has been some time since I created this project, so I am not sure anymore which SdFat library I used. And looks like everyone creates their own.

So, to make things easier for you (I know its cheating) I have uploaded my SdFat to the sourceforge site.

Please grab that one and give it a try. It should solve the problem.

Please let me know if it works.

  Are you sure? yes | no

Mark Bramwell wrote 11/20/2015 at 18:14 point

oops!  Unless you can read my mind, you need the URL for the screen shot:

 www . foxhollow . ca / CPMduino.png              <== removes spaces for picture

user libraries are installed here:   C:\Users\mbramwell\Documents\Arduino\libraries\SdFat

stock libraries are here:  C:\Program Files (x86)\Arduino\libraries

If you un-install arduino, only the C:\Program Files (x86)\Arduino\libraries gets removed.  The user libraries stay in your c:\users\...\documents folder.  I wonder if you have a SdFat library stored there.

  Are you sure? yes | no

Marcelo Dantas wrote 11/20/2015 at 18:41 point

Oh ok ... I am an Arduino newbie, so let me check there for something... and ...

Tada... there's a SdFat library there. Removing it gets me to the obvious SdFat.h missing, so that's definitely the one being used.

It came from

  Are you sure? yes | no

Mark Bramwell wrote 11/20/2015 at 18:06 point

newly installed OS.  Arduino installed for the 1st time.  Your results are promising.  

You do not mention sdFat. 

I just removed sdFat from libraries and of course I get "fatal error: SdFat.h: No such file or directory".  Did you just happen to have a SdFat directory in documents\Arduino\libraires ?

I have placed a screenshot of my library menu open.  Look way down at the bottom.  See under Contributed libraries?  It shows SdFat.  Since you do not mention that you added SdFat, I wonder if it shows up on that list. If yes, the library is in your userid Documents folder and not in your c:\program files(86)\arduino\libraries folder (and probably survived your PC reload if you have backed up your documents folder).

FYI: I have more than 1 laptop.  I have installed on one laptop and installed on the other. I have been playing with arduino boards for a LONG time. This feels like a file/library difference problem.

  Are you sure? yes | no

Mark Bramwell wrote 11/20/2015 at 05:43 point

I have given it a try.  Still no go.  "abstraction_arduino.h:189:7: error: 'class SdFile' has no member named 'getFilename'"

The arduino community seems broken. versus

The IDE is 1.6.6   It has the most features but less compatible.  I had to change some other sketches to make them compile with the latest IDE.

The IDE is 1.7.7 but seems to be older. My old sketches compile without changes but the IDE does not have the boards & library updating features.

There are MANY sdfat libraries out there.  I have tried them all.  They are all very similar but not identical. If you manage to get it to compile on your computer, let me know exactly what software components you used.  I'll keep trying random things in case I get lucky.

If someone has this working, exactly what IDE version did you use and what sdfat library?

  Are you sure? yes | no

Marcelo Dantas wrote 11/20/2015 at 14:31 point

Don't worry ... we will get to the bottom of this.

I will put my lab back together later today and rebuild the code.

  Are you sure? yes | no

Marcelo Dantas wrote 11/20/2015 at 17:25 point

I have followed these steps:

1 - Went to, downloaded and installed Arduino 1.6.6;

2 - Added support to Arduino DUE under tools->board->boards manager;

3 - Ran all updates for Arduino (the IDE offered updates, which I accepted);

4 - Compiled the code;

5 - Got a few warnings regarding use of NULL on arith. and string conversion;

6 - Loaded the code onto the board and it seems to work with no glitches.

Not sure if it inherited anything from the previous installation, which I removed completely, but all I needed seemed to be available and I didn't have to import any extra libraries.

Do you have multiple Arduino IDEs installed? Maybe the system PATH is pointing to wrong compilers?

  Are you sure? yes | no

Mark Bramwell wrote 11/19/2015 at 15:42 point

I was using arduino 1.6.5 with the lastest sdfat lib from greiman.  Lots of errors.  

A few days ago I updated to the 'just released' 1.6.6.  Different errors but they all seem to relate to the sdfat library.  Specifically I get "CPMduino:9: error: 'SdFat' does not name a type     SdFat SD;"

I have gone through the arduino IDE and updated all boards and libraries to the latest. I feel if the root cause of the first error is resolved, all the other SD errors would disappear.

  Are you sure? yes | no

Marcelo Dantas wrote 11/19/2015 at 16:22 point

I think this is the one I used:

Please give it a try and let me know.



  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates