RetroBrew Computers Forum
Discussion forum for the RetroBrew Computers community.

Home » RBC Forums » General Discussion » CP/M on AVR (ATmega88) (forking Takashi Toyoshimas CP/Mega88 )
CP/M on AVR (ATmega88) [message #3357] Mon, 21 August 2017 03:48 Go to next message
rhkoolstar is currently offline  rhkoolstar
Messages: 256
Registered: October 2015
Senior Member
Hi all,

A while ago, when I was considering using an Arduino for an i/o co-processor, Alan Cox suggested that at that point I could just as well use the Arduino to emulate the whole Z80 system. This suggestion stuck with me, and I decided to look into it further.
I stumbled on the CP/Mega88 project of Takashi Toyoshima on github <https://github.com/toyoshim/cp-mega88>, which is an i8080 emulator, console and SD-card interface, supporting 128 kBytes of static RAM (multiplexed Address Hi/Lo/Data), all in a single ATmega88 AVR (and also running in various other systems)
This is a work in progress, it needed some work in the SD-card and the FAT code. (I issued a pull request with the changes) and now it works quite nicely.
I abandoned using a FAT image to boot from, because it slows down disk access quite a lot (in particular on larger disks). Deleting the FAT code also gave me a lot more space on the AVR.
Then I added some extra features like a 32k banked memory system, bigger disk support and several enhancements of the "monitor" (which runs in the AVR).
Continuing with a dedicated CP/M 2.2 BIOS and CP/M 3.0 BNKBIOS and a dual boot option, using 4 8 MB diskdrives, I ended up with a 59k CP/M 2.2 or 61k CP/M 3.0 system with 32 MB disk space.
I was quite surprised to see the speed to be comparable to 2.5 - 3 MHz (compared to a 25 MHz searle-FPGA) using "ASM CPM22.ASM" as a benchmark.

I decided I needed a PCB, so that came out to be a 40x60 mm board using SMD parts, compatible with a 5V FTDI cable. (or 3v3 if you so desire)
The total building cost was less than $4.50
index.php?t=getfile&id=572&private=0
1	PCB		0.77
1	SRAM		1.57	Bs62lv1027
2	74HC374		1.20
1	ATMEGA88	0.49
1	XTAL 20 MHz	0.23
1	AMS117-3.3	0.03
1	TF card Socket	0.11
7	C		0.03
2	R		0.01
1	D		0.02
			-----
	TOTAL		4.47	(rounding error)

Next logical step would be to use a serial SRAM (23LC1024) which would save another $ 0.70, but would undoubtably slow down the system. It would free up a lot of pins on the AVR so extra features could be implemented (like handshake, more I/O etc)...

I'll update my builderpages shortly, detailing the whole project, including sources and gerbers. (and yes, I have some spare boards too)

Rienk


  • Attachment: CPMega88.jpg
    (Size: 156.40KB, Downloaded 1253 times)
  • Attachment: CPMega88.pdf
    (Size: 94.28KB, Downloaded 163 times)
Re: CP/M on AVR (ATmega88) [message #3358 is a reply to message #3357] Mon, 21 August 2017 08:22 Go to previous messageGo to next message
gkaufman is currently offline  gkaufman
Messages: 140
Registered: October 2015
Senior Member
Very nice! Can't wait to see the builderpage.
Re: CP/M on AVR (ATmega88) [message #3360 is a reply to message #3358] Tue, 22 August 2017 07:49 Go to previous messageGo to next message
will is currently offline  will
Messages: 182
Registered: October 2015
Senior Member
This looks like a fun project -- and nice to see a project using surface-mount ICs!

May I ask why you chose an ATmega88 instead of the ATmega328 (with much larger internal memories)?
Re: CP/M on AVR (ATmega88) [message #3361 is a reply to message #3360] Tue, 22 August 2017 10:41 Go to previous messageGo to next message
rhkoolstar is currently offline  rhkoolstar
Messages: 256
Registered: October 2015
Senior Member
Hi Will,

three reasons, 1: That's what toyoshim used. 2: it's cheaper ($1.31 vs $0.49) 3: I had them available.
Right now there is plenty of space for this project I have some 700 bytes flash memory free. RAM is mostly used for SD card sector buffer (512 bytes) and console fifo (32 bytes) and all the variables. Now if you would want to implement a Z80 instead of a 8080 you probably need something bigger.

I use this project as a learning process, working with AVR's and the avr-gcc toolchain. And I'm only just beginning...

An ATmega328 fits on the same board and I have 20 boards (well... 19 now). Let's just say this project has possibilities.

I thought it fun to do an SMD project. The components are generally cheaper and boards can be smaller. You just need to re-learn something about soldering, which is no big deal, really. I won't go finer than 0.8 mm spacing though.

Rienk
Re: CP/M on AVR (ATmega88) [message #3362 is a reply to message #3361] Tue, 22 August 2017 10:49 Go to previous messageGo to next message
will is currently offline  will
Messages: 182
Registered: October 2015
Senior Member
Hey

I have also recently started using SMD and I was amazed to find how easy it is with the right tools (ie a temperature controlled iron and liquid flux). It's also faster than through-hole soldering (for ICs -- arguably a bit slower for passives).

Interesting project.
Re: CP/M on AVR (ATmega88) [message #3363 is a reply to message #3362] Tue, 22 August 2017 11:17 Go to previous messageGo to next message
Andrew B is currently offline  Andrew B
Messages: 438
Registered: October 2015
Location: Hawthorne, CA
Senior Member
Administrator
I have been looking for a 'get better at SMD soldering' project, the one time I did it it was a disaster. But that was early on in my soldering experience in general, several 1000s of pins later and I'm sure it would be better. There have been a few projects where using 1 or 2 SMD chips could save a lot of space on the board.

Re: CP/M on AVR (ATmega88) [message #3365 is a reply to message #3363] Tue, 22 August 2017 12:02 Go to previous messageGo to next message
plasmo is currently offline  plasmo
Messages: 437
Registered: March 2017
Location: New Mexico, USA
Senior Member
The more I worked with SMT, the more I prefer it. I can assemble a board so much faster, especially with passive parts because I don't have to flip the board over, solder while holding down the component and then trim the leads. Another hidden advantage is the parts are so small that thousands of them can fit inside a small tray and many such trays fit in a small box that sits right on the bench. I don't have to move around to put together a board, all parts are right there at my finger tips. This tray contains half of my common 1206 resistors. 6 of the trays fit in a 4"x5"x5"deep "bug box" that Jameco used to sell.
index.php?t=getfile&id=575&private=0
Re: CP/M on AVR (ATmega88) [message #3366 is a reply to message #3363] Tue, 22 August 2017 12:20 Go to previous messageGo to next message
rhkoolstar is currently offline  rhkoolstar
Messages: 256
Registered: October 2015
Senior Member
There is one special tool I use. it is a cheap steel tweezers in which I filed a notch in the ends. I can hold a part in place and hold it down without pinching too hard.
index.php?t=getfile&id=577&private=0
index.php?t=getfile&id=578&private=0
With this soldering Cs and Rs is really easy. I use a Weller magnastat WTCP-S with a 1 mm tip (nr 7) and 0.4 mm rosin core solder wire. (and occasionally solder wick ;-)

I think it is fun stepping out of your comfort zone and doing something new

[Updated on: Tue, 22 August 2017 12:26]

Report message to a moderator

Re: CP/M on AVR (ATmega88) [message #3372 is a reply to message #3366] Thu, 24 August 2017 07:02 Go to previous messageGo to next message
rhkoolstar is currently offline  rhkoolstar
Messages: 256
Registered: October 2015
Senior Member
Hi all,

I uploaded the project files to my builderpages here: https://www.retrobrewcomputers.org/doku.php?id=builderpages: rhkoolstar:start

Please let me know if you have suggestions, find mistakes, or know of a better way of doing things.

If you want a PCB, they are 75 cents. P&P for upto 2 boards is is 1.25

Rienk
icon14.gif  Re: CP/M on AVR (ATmega88) [message #3388 is a reply to message #3372] Tue, 29 August 2017 19:47 Go to previous messageGo to next message
positron is currently offline  positron
Messages: 78
Registered: November 2015
Location: Buenos Aires, Argentina
Member
Hi Rienk, impressive work as usual ! Maybe the smallest CP/M system ever ? I'll PM you for a couple of boards. Thanks for sharing.

JL.
Re: CP/M on AVR (ATmega88) [message #3418 is a reply to message #3357] Mon, 04 September 2017 15:28 Go to previous messageGo to next message
oscarv is currently offline  oscarv
Messages: 15
Registered: October 2015
Junior Member
Hi,

I'm showing RKoolstar's board as part of a small collection of Retrobrews at VCF MidWest next weekend. Smallest system ever shown at a Vintage Computer Festival, I expect.

Regards,

Oscar.
Re: CP/M on AVR (ATmega88) [message #3430 is a reply to message #3357] Sun, 10 September 2017 02:05 Go to previous messageGo to next message
just4fun is currently offline  just4fun
Messages: 127
Registered: May 2017
Location: Dark side of the Moon
Senior Member
Wow!! Really impressed... and using only a 8kB flash... Shocked

[Updated on: Sun, 10 September 2017 02:05]

Report message to a moderator

Re: CP/M on AVR (ATmega88) [message #3447 is a reply to message #3430] Tue, 12 September 2017 12:57 Go to previous messageGo to next message
nealcrook is currently offline  nealcrook
Messages: 119
Registered: October 2015
Location: UK
Senior Member
Hi Rienk,

nice board, nice work. Seeing such a small neat board has made me think twice about doing a SM design. Thanks for sharing - especially the PCB files. I really must spend some time having a play with KiCAD. This has (re)fuelled my enthusiasm for making a 6809 version (more elsewhere).

I'd be really interested if you and just4fun can agree on a benchmark and assess the relative speed of (1) AVR knife-and-forking the pins of a real Z80 vs (2) AVR just doing all the work

Just one quibble:

>> just as well use the Arduino to emulate the whole Z80 system

it's a tiny bit disappointing that you have to plug this into a PC (which could happily emulate the AVR emulating a z80 and *still* have enough spare processing power to view some kitten videos on youtube)

On the subject of plugging in to a PC, it looks as though your board is small enough to be sneaked inside a PC keyboard. If you chose one with an integral hub you could grab power and USB internally. Plug the keyboard in to a PC then freak people out by bringing up hyperterm and magically starting up.. wordstar!

Neal.
Re: CP/M on AVR (ATmega88) [message #3449 is a reply to message #3447] Wed, 13 September 2017 00:07 Go to previous messageGo to next message
rhkoolstar is currently offline  rhkoolstar
Messages: 256
Registered: October 2015
Senior Member
Hi Neal,

To run on a glass terminal a lower baudrate is required, preferably set auto (tap the spacebar a few times).
You could also look at an ATMega16U which comes with built-in USB (lowest price about $0.70)

You know, To build a complete system you only need a pi zero to run the whole show. Same price class, similar footprint. But where's the fun in that?

My current focus is on adding an RTS line and experiment with serial SRAM -- baby steps

Rienk
Re: CP/M on AVR (ATmega88) [message #3451 is a reply to message #3449] Wed, 13 September 2017 14:10 Go to previous messageGo to next message
nealcrook is currently offline  nealcrook
Messages: 119
Registered: October 2015
Location: UK
Senior Member
>> only need a pi zero to run the whole show. Same price class, similar footprint. But where's the fun in that

yes, I completely agree.

I have an Arduino Leonardo (ATMega32u4 with built-in USB) heading my way on a slow boat from China; I'll use this for my prototyping. The Arduino IDE is a clean simple environment to work in, even though it doesn't give any support in the way of advanced debugging.

Neal.
Re: CP/M on AVR (ATmega88) [message #3455 is a reply to message #3447] Thu, 14 September 2017 10:15 Go to previous messageGo to next message
just4fun is currently offline  just4fun
Messages: 127
Registered: May 2017
Location: Dark side of the Moon
Senior Member
nealcrook wrote on Tue, 12 September 2017 12:57
Hi Rienk,
I'd be really interested if you and just4fun can agree on a benchmark and assess the relative speed of (1) AVR knife-and-forking the pins of a real Z80 vs (2) AVR just doing all the work

Hi,
give me a test program and I'll run it... Very Happy


About AVR emulation...

Using an Atmega128A (about 1$) you have 128kB flash and a lot of pins. Plus, it is the only of its "family" that has internal HW to drive external SRAM, so a 3 ICs system shuld be possible.

The internal interface consists of:
• AD7:0: Multiplexed low-order address bus and data bus.
• A15:8: High-order address bus.
• ALE: Address latch enable.
• RD: Read strobe.
• WR: Write strobe.
So only a 74HCT373/74HCT573 should be enough...

Currently I haven't time for further "investigations" about this because I'm playing with CPLD/FPGA stuff, and I've just "released" a custom CPLD dev board (with an STM32F103 Arduino embedded)

https://farm5.staticflickr.com/4369/36716128212_9eb40d9171_z.jpg

and the next project will probably be a FPGA dev board "Multicomp" compatible...

[Updated on: Thu, 14 September 2017 10:18]

Report message to a moderator

Re: CP/M on AVR (ATmega88) [message #3456 is a reply to message #3455] Thu, 14 September 2017 11:11 Go to previous messageGo to next message
rhkoolstar is currently offline  rhkoolstar
Messages: 256
Registered: October 2015
Senior Member
I have to think about a representative benchmark. Problem is that the emulation is not equally efficient with all the instructions. Also memory and disk access should be considered and CP/M BIOS overhead will play a significant role. (This board uses a very lean BIOS). I used the assembly of CP/M 2 as a rough benchmark, just to get an idea.

Currently I like to see how far I can get using the mega88. There is still flash left over (700 bytes) and the chip runs comfortably at 20 MHz. The emulation lacks interrupt support, which will be a problem when MP/M is desired, but MP/M ... really?

Rienk

Re: CP/M on AVR (ATmega88) [message #3457 is a reply to message #3456] Thu, 14 September 2017 15:04 Go to previous messageGo to next message
positron is currently offline  positron
Messages: 78
Registered: November 2015
Location: Buenos Aires, Argentina
Member
Hi all, maybe this helps as a standard for Z80 emulation benchmark tests http://mdfs.net/Software/Z80/Exerciser/
Glad to see a renewed interest in 8 biters and CP/M compared to the wave of latest "big iron" 68K and 80X86 projects Very Happy

Cheers, positron.
Re: CP/M on AVR (ATmega88) [message #3459 is a reply to message #3457] Thu, 14 September 2017 23:43 Go to previous messageGo to next message
rhkoolstar is currently offline  rhkoolstar
Messages: 256
Registered: October 2015
Senior Member
CP/Mega88 is i8080 though. Also it is a simple emulator. it is not 'counting' t-cycles.
Also the exerciser does not consider disk access.

But a good place to start. Thanks.

I think that the problem with CP/M (and Z80) is that it is (too) well documented, making it less challenging.

Rienk

[Updated on: Thu, 14 September 2017 23:49]

Report message to a moderator

Re: CP/M on AVR (ATmega88) [message #3463 is a reply to message #3459] Sat, 16 September 2017 07:39 Go to previous messageGo to next message
etchedpixels is currently offline  etchedpixels
Messages: 226
Registered: October 2015
Senior Member
The real challenge with Z80 is getting it to work fast and in a very small space. The instruction set is extremely logical and the instructions split into 2 bit/3 bit/3 bit chunks which allows for a tiny interpreter but that then makes it very hard to run fast.

Re: CP/M on AVR (ATmega88) [message #6822 is a reply to message #3463] Thu, 21 November 2019 19:32 Go to previous messageGo to next message
gkaufman is currently offline  gkaufman
Messages: 140
Registered: October 2015
Senior Member
Rienk -

I realize this is an older thread, but I put together one of these CP/Mega88 PC's tonight - very cute!

Curious if there was any further work or updates?

- Gary
Re: CP/M on AVR (ATmega88) [message #6826 is a reply to message #6822] Fri, 22 November 2019 23:55 Go to previous messageGo to next message
rhkoolstar is currently offline  rhkoolstar
Messages: 256
Registered: October 2015
Senior Member
This project has been on a backburner for a while. Any suggestions?

Rienk
Re: CP/M on AVR (ATmega88) [message #6827 is a reply to message #6826] Sat, 23 November 2019 08:21 Go to previous messageGo to next message
gkaufman is currently offline  gkaufman
Messages: 140
Registered: October 2015
Senior Member
Rienk -

It would be fun to see the design ported to a USB stick design. Plug'n'play CP/M!
USB at one end, SD card at the other.

- Gary
Re: CP/M on AVR (ATmega88) [message #6829 is a reply to message #6827] Sat, 23 November 2019 10:10 Go to previous messageGo to next message
little_john is currently offline  little_john
Messages: 2
Registered: October 2019
Junior Member
There are a couple of AVR-based CP/M systems using the Arduino platform - dunno if there are any useful ideas there ?
https://forum.arduino.cc/index.php?topic=464410.0 (nano)
https://weblambdazero.blogspot.com/2016/07/cpm-on-stick_16.h tml (due)
Re: CP/M on AVR (ATmega88) [message #6834 is a reply to message #6829] Sun, 24 November 2019 00:55 Go to previous message
rhkoolstar is currently offline  rhkoolstar
Messages: 256
Registered: October 2015
Senior Member
Thanks for the ideas,

Integral USB could probably be achieved by using a ATmega32U4, but that would add some $2.50 to the total cost. This is compensated somewhat by eliminating the need for a USB-serial interface. On the other hand, the current configuration allows you to implement RS-232 as well as USB.

I don't know if using the SD card for system RAM is such a good idea. I am toying with the idea to use serial SRAM (23LC1024) instead. That would reduce the card size by at least 50%, and would free up some pins for extra I/O, like handshake. Serial SRAM is comparable in price with the current configuration. It will make the system slower though.

I kind of like the idea that a lowly ATmega88 can do for less than a dollar what we used to pay in excess of $1000 for in 1980.

Also consider that for a minimal extra cost you can implement a much bigger system in a raspberry pi zero (W)
Previous Topic: Looking for DIN41612 Library
Next Topic: Project CheapBus


Current Time: Sun Jan 19 05:05:03 PST 2020

Total time taken to generate the page: 0.01279 seconds