Arduino Forum

Community => Exhibition / Gallery => Topic started by: FoxyLab on Mar 21, 2017, 04:51 pm

Title: CP/M computer on Arduino Nano 3.0
Post by: FoxyLab on Mar 21, 2017, 04:51 pm
Greetings to all lovers of Arduino and old school computing! Nostalgia for the eight-bit computers of my youth led me to this project :-) - CP/M 2.2 computer from ... what would you think? ... Arduino Nano 3.0!

For weeks two or three I made the i8080 processor emulator for Arduino Nano (it passes the test from MICROCOSM) and adapted the CP / M.
The main problem - Arduino has only 2 (!) KB of RAM. But we also have an SD card - I made a 4-line cache (32 bytes) to this card, and the card itself emulated all 64 KB of RAM. Although I applied the most primitive cache management algorithm, the speed of work is not so bad.
At the same time, this card also emulates four floppy disks.

Here's the quick-and-dirty prototype of my work:
(https://acdc.foxylab.com/sites/default/files/cpm_mk1.jpg)

Yes, I did not use the adapter for the card, I inserted it into the connector of the cable from the five-inch drive. :-)

To communicate with a computer, I use a terminal program (in the future I plan a PS/2 keyboard and an LCD screen or connect to a TV).

Here is a screenshot of the memory check:
(https://acdc.foxylab.com/sites/default/files/cpm_memtest.png)

CP/M Download:
(https://acdc.foxylab.com/sites/default/files/cpm_loading.png)

CPU Test:
(https://acdc.foxylab.com/sites/default/files/cpm_mctest.png)

DIR command:
(https://acdc.foxylab.com/sites/default/files/cpm_dir.png)

My first program in BASIC for the past twenty (!)))) years:
(https://acdc.foxylab.com/sites/default/files/cpm_tinybas.png)
(I launched TinyBASIC).

Are you interested in such a project?
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: Groove on Mar 21, 2017, 08:57 pm
{Claps}. Bravo!
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: FoxyLab on Mar 22, 2017, 02:32 am
{Claps}. Bravo!
Thanks a lot!
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: Isaac96 on Mar 22, 2017, 02:48 am
That is great!
Another person (i think it was on here) used a Mega1284, which was probably easier relatively speaking. One thing-there is a VGAout library somewhere. You might be able to output to a vga screen and have a command line!
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: FoxyLab on Mar 22, 2017, 03:41 am
That is great!
Another person (i think it was on here) used a Mega1284, which was probably easier relatively speaking. One thing-there is a VGAout library somewhere. You might be able to output to a vga screen and have a command line!
Many thanks! I plan to add PS/2 keyboard and LCD screen (or TV-out - but this required additional microcontroller as VGA-controller).
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: Isaac96 on Mar 22, 2017, 04:34 am
Awesome. That sounds amazing. Please post when that is complete.
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: FoxyLab on Mar 23, 2017, 03:01 pm
I uploaded on YouTube realtime video of my project in action:
https://youtu.be/LHFmt3qWAuY (https://youtu.be/LHFmt3qWAuY)
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: thomai on Mar 23, 2017, 07:22 pm
Simply awesome!!!

But why didn't you use a SPI RAM extension?
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: petersieg on Mar 23, 2017, 08:33 pm
Where is the source? ;-)
Would like to give it a try..
Very interesting to use a 64kb area on sd card to mimick ram memory.
I assume the 4 floppy images are dd-ed on 4 partitions of the sd card?

Please keep this code as a separate (version 1) project, before you introduce ps/2 kb und display.

thx,

Peter
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: FoxyLab on Mar 23, 2017, 10:04 pm
Simply awesome!!!

But why didn't you use a SPI RAM extension?
Thanks!
In future probably as an option (Ferroelectric RAM).
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: FoxyLab on Mar 23, 2017, 10:15 pm
Where is the source? ;-)
Would like to give it a try..
Very interesting to use a 64kb area on sd card to mimick ram memory.
I assume the 4 floppy images are dd-ed on 4 partitions of the sd card?

Please keep this code as a separate (version 1) project, before you introduce ps/2 kb und display.

thx,

Peter
1. I will uploaded source in my GitHub repository - I believe, by the beginning of next week.
2. I use 4 GB SDHC Card, so i trade free space for simplifying - i write one line cache at the beginning of each sector (64 bytes of 512 bytes)   (cache has 8 lines of 64 bytes)  ->  65536/64 sectors to all RAM.
3. No, i dont use partitions on SD Card - raw read/write only.
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: petersieg on Mar 24, 2017, 09:11 am
Thx. Would be glad if you upload also your sd card image so that one can write it directly with dd on a card.

Peter
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: FoxyLab on Mar 24, 2017, 09:53 am
Thx. Would be glad if you upload also your sd card image so that one can write it directly with dd on a card.

Peter
O.K.
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: pito on Mar 24, 2017, 05:05 pm
I've got stm32duino (stm32F103zet6 board) with 64kB internal and 512kB of external sram (wired via FSMC). The 512kB of sram could be used for the heap. I can allocate the 64kB of CP/M's RAM with malloc() in that 512kB space easily.
So I may try to run your code on it, when available..
FYI:
External sram on stm32duino (http://stm32duino.com/viewtopic.php?f=28&t=1651&p=25394#p22576)


Title: Re: CP/M computer on Arduino Nano 3.0
Post by: FoxyLab on Mar 24, 2017, 05:52 pm
I've got stm32duino (stm32F103zet6 board) with 64kB internal and 512kB of external sram (wired via FSMC). The 512kB of sram could be used for the heap. I can allocate the 64kB of CP/M's RAM with malloc() in that 512kB space easily.
So I may try to run your code on it, when available..
FYI:
External sram on stm32duino (http://stm32duino.com/viewtopic.php?f=28&t=1651&p=25394#p22576)
Thanks!
But my target was Nano. For fun i plan in future connect Nano to 32+32 KBytes Ferroelectric RAM (FRAM) (~1.2$ on eBay) as option.
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: FoxyLab on Mar 25, 2017, 08:55 pm
I uploaded very draft source code of my project to Github:
https://github.com/Dreamy16101976/cpm4nano (https://github.com/Dreamy16101976/cpm4nano)

I did the emulation of ports 0 and 1 in Altair-style and run Altair TinyBASIC without (!) CP/M. He works quick!
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: spcrngr on Mar 28, 2017, 04:59 am
This is very impressive, nice work!
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: FoxyLab on Mar 28, 2017, 09:31 am
This is very impressive, nice work!
Thank you very much!
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: FoxyLab on Mar 31, 2017, 03:32 pm
To simplify the configuration of the CP/M for the current RAM size, I extracted the CCP and BDOS images from MOVCPM.COM and analyzed (using the program, of course) the differences between this template image and the real image of the system with 62 KByte. The result is the project getcpm - https://github.com/Dreamy16101976/getcpm (https://github.com/Dreamy16101976/getcpm)
When you run getcpm.exe, you need to specify the memory size in kilobytes (XX) and the desired serial number of the CP/M system (6 bytes in hexadecimal, YYYYYYYYYYYY), after the configuration is done, the CPMXXK.SYS file is created and its eight-bit checksum is specified:
(https://acdc.foxylab.com/sites/default/files/getcpm_1.png)

The program, using the CPMDIFF.SYS file, corrects the addresses in the CPM00K.SYS file by configuring CCP and BDOS for the specified amount of RAM:
(https://acdc.foxylab.com/sites/default/files/getcpm_2.png)

The program itself is written on Go and compiled by the command go build getcpm.go
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: FoxyLab on Apr 01, 2017, 10:44 am
I found and fixed an error in INR M/DCR M emulation.
Now the TYPE command works correctly!!!
The emulator is almost ready to use widely.
I will write instructions on how to prepare a SD-card for use in the emulator.
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: FoxyLab on Apr 02, 2017, 08:43 am
I added an LRC-checksum for the memory data when writing/reading to the SD-card. While failures were not.
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: FoxyLab on Apr 05, 2017, 12:09 am
I made the input from the console more versatile - through interrupts - to connecting the PS/2 keyboard in the future + added a command R monitor to reset the Arduino.
Also i did 200 runs of the memory test (added a command to the monitor) - failures not detected:
(https://acdc.foxylab.com/sites/default/files/cpm_memtests.png)
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: FoxyLab on Apr 09, 2017, 08:05 pm
Using emulation of address and data buses, as well as internal registers (W, Z, ACT, TMP), made emulation of microoperations as close as possible to the "iron" processor + with #define made the emulation code much more visible. The new code is already laid out on GitHub.
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: FoxyLab on Apr 12, 2017, 01:06 am
According to the test results, the random access time to the emulated memory card was about 7 milliseconds.
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: FoxyLab on Apr 15, 2017, 07:59 pm
Because of the use of caching, the average access time with sequential access to memory is about 80 microseconds.
I used the BASIC test (in the TINYBASIC interpreter) to evaluate the effect of the cache on performance in the real task:
(https://acdc.foxylab.com/sites/default/files/cpm_basic_test.png)
(The size of the cache line is 64 bytes)
Number of cache lines runtime (seconds)
2 .................................... 345
4 ................................... 155
6 .................................... 80
8 .................................... 60
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: FoxyLab on Apr 19, 2017, 09:40 pm
I ran the Ada language compiler on my Arduino !!!

Compilation of the program TOWERS.ADA for solving the problem of the "Hanoi Tower":
(https://acdc.foxylab.com/sites/default/files/towers_ada_comp.png)

Running the compiled program TOWERS.COM:
(https://acdc.foxylab.com/sites/default/files/towers_ada_3.png)
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: FoxyLab on Apr 22, 2017, 05:59 pm
Changed the approach to emulating the floppy disks - allocated on the SD card the area for storing the contents of 100 floppy disks and with the monitor command Z i "insert" a floppy disk into one of the drives A, B, C or D
(for example, the ZB02 command mounts a floppy disk with the number 02 in drive B)
(https://acdc.foxylab.com/sites/default/files/cpm_floppy.png)
The numbers of "inserted" floppies are stored in the Arduino EEPROM and are restored when the emulator is restarted.
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: FoxyLab on Apr 27, 2017, 08:05 pm
I made an emulation of the memory management device (MMU) with switching banks, which allowed access to 512 KByte of memory.
I divided the address space 0x0000 ... 0xFFFF into 16 blocks (with numbers from 0x0 to 0xF) of 4 KByte in size. Each block can be mapped to one of 8 banks (the size of the bank is 64 KByte). The correspondence of banks to blocks is determined by the values ​​(bank numbers from 0 to 7) in a set of 16 registers (only bank 0 is active when the emulator is started).
To specify the bank number for a specific block, two output commands are used in the port:
OUT D0, block number
OUT D1, banknumber
Also, you can use the YXY monitor command to switch the X memory unit to the Y memory bank.
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: FoxyLab on Apr 30, 2017, 07:36 am
Testing for 8 banks of memory:
(https://acdc.foxylab.com/sites/default/files/%D1%81pm_start_banks.png)
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: FoxyLab on May 17, 2017, 08:17 pm
cpm4nano Mk II
(used an adapter to connect a microSD-card)
(https://acdc.foxylab.com/sites/default/files/cpm_mk2.jpg)
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: Budvar10 on May 18, 2017, 07:49 am
+ ;)
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: petersieg on May 18, 2017, 09:57 am
Hmm. Just gave it a try with Arduino 1.0.6 (I know that it is very old).
1. Gives conflict with standard arduino SD library - better to rename your spinoff to something that does not give a conflict with the standard libs.
2. Resulting sketch ist to big for Nano/Mini Pro with atmega328:

Binäre Sketchgröße: 33.386 Bytes (von einem Maximum von 30.720 Bytes)
processing.app.debug.RunnerException: Sketch zu groß;

??

BTW: I assume the ps2 files are just there for future use and not yet used in the project?
Also some wiring information would be making it probably easier.
And where can I locate the ADA compiler for CP/M?

Also it would be a good idea, the let any somewhat stable version there as a release when you start working on a new/anhanced version.. so just have one bucket of code that is a work in progress ist not good.

Peter
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: FoxyLab on May 26, 2017, 08:20 am
Hmm. Just gave it a try with Arduino 1.0.6 (I know that it is very old).
1. Gives conflict with standard arduino SD library - better to rename your spinoff to something that does not give a conflict with the standard libs.
2. Resulting sketch ist to big for Nano/Mini Pro with atmega328:

Binäre Sketchgröße: 33.386 Bytes (von einem Maximum von 30.720 Bytes)
processing.app.debug.RunnerException: Sketch zu groß;

??

BTW: I assume the ps2 files are just there for future use and not yet used in the project?
Also some wiring information would be making it probably easier.
And where can I locate the ADA compiler for CP/M?

Also it would be a good idea, the let any somewhat stable version there as a release when you start working on a new/anhanced version.. so just have one bucket of code that is a work in progress ist not good.

Peter
I compiled the project succesfully on Arduino 1.6.6 (on Arduino 1.8.x - fail with PROGMEM).  Required library files (some are slightly changed!) placed in project folder (Sd2Card.h, SD.h etc).
I upload on GitHub today last project version.
For this code:
"Sketch uses 30,436 bytes (99%) of program storage space. Maximum is 30,720 bytes.
Global variables use 1,465 bytes (71%) of dynamic memory, leaving 583 bytes for local variables. Maximum is 2,048 bytes."

Yes, PS/2 related files - for future use.

I'm working on a wiring drawing.

ADA compiler - i will upload later.

Best regards, Alexey
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: FoxyLab on May 26, 2017, 08:26 am
+ ;)
Thanks!
Title: Re: CP/M computer on Arduino Nano 3.0
Post by: FoxyLab on May 27, 2017, 06:57 am
P.S. Ada compiler for CP/M - https://acdc.foxylab.com/ada.zip (https://acdc.foxylab.com/ada.zip)