Legacy Z80  meets AVR - Page 1
Forum section: electronics / general

author: commie
author_rank: Frequent Contributor
timestamp: November 03, 2021, 06:02:42 pm
content: Hi Guys,This circuit,shown in the link, shows a functional Z80 system with an AVR micro controller.https://cdn.hackaday.io/files/1599736844284832/A040618%20-%20SCH.pdfYou maybe wondering, why?, well the contemporary uC's are feature rich in peripherals, such as uart, timers,eeprom and clocks, etc and are low cost. Now, if you find yourself designing a Z80 system today(for whatever reason) your gonna be looking at maybe Z80 ctc, duart, 8255 ports and/or Z80 pio support chips right?Although these legacy support chips are still available new, they are very, very expensive and as time progresses, they are set to get even more expensive.Somebody at 'just4fun' sat down to try and figure out how a Z80 cpu can utilize and have access to the peripherals in an atmega32 and it looks like it's been achieved. Google z80 mbc2.I have been head scratching since seeing the schematic. it looks like the AVR writes z80 hex code into the ram and then releases control to the z80 cpu but how does the AVR manage to write code to ram since the address bus is void. Check the schematics for yourself.Cheers

author: Ian.M
author_rank: Super Contributor
timestamp: November 03, 2021, 07:20:54 pm
content: The ATmega32 has the Z80 control signals and provides the Z80 CLK so can determine the start of an instruction cycle, and controls the RAM's CS2 signal so can selectively disable it and stuff instructions (and data) on the data bus e.g. to set up the HL register with the RAM address then repeatedly stuff INI instructions followed by data bytes to transfer the data to RAM. Returning to the previously executing program simply requires careful preservation of registers and either restoring the previous PC (saved off the data bus by stuffing a CALL or RST instruction), or cancelling out the extra instruction address increments by careful use of negative JR instructions.

author: westfw
author_rank: Super Contributor
timestamp: November 03, 2021, 07:21:27 pm
content: QuoteIt's all explained in the source code at the project:https://hackaday.io/project/159973-z80-mbc2-a-4-ics-homebrew-z80-computerBasically, the AVR forces instructions to load memory onto the databus:Code:LD HL, addrLD (HL), dataINC HL(those are position independent, so they don't care what the current PC address is. Though presumably there will be a RESET or something to put the Z80 into a known state shortly after loading memory.)I sort-of like the original MBC better; it had a bunch of address lines (9?) that could be driven directly by the AVR, so loading up a Z80 bootloader into the first 512 bytes was "obvious" (but MBC2 frees up a a bunch of AVR pins for "other functions.")

author: SiliconWizard
author_rank: Super Contributor
timestamp: November 03, 2021, 07:52:56 pm
content: I've seen a number of projects using a vintage CPU and a microcontroller, in particular an AVR one. This certainly isn't the first or only project of this kind.More recently, I've seen a project using a 6502 and a RP2040 as an EPROM emulator, using the PIO for interfacing it. Fun and neat.Although vintage CPU boards required a significant number of logic parts, that's part of the vintage spirit. I for one am not sure I see the point of designing something "vintage" with a mix of old and modern chips. If you're not going to go 100% vintage, why not go all the way and just implement everything in a FPGA or as emulation on a recent MCU/CPU? Of course, to each their own...!

author: commie
author_rank: Frequent Contributor
timestamp: November 03, 2021, 08:09:19 pm
content: Quote from: westfw on November 03, 2021, 07:21:27 pmYeah, thanks westfw, you have put me on the right track.I find this stuff fascinating

author: commie
author_rank: Frequent Contributor
timestamp: November 03, 2021, 08:18:25 pm
content: Quote from: SiliconWizard on November 03, 2021, 07:52:56 pmI hear what you say but legacy cpu's do have a place, they are Von Neumann mpu's which renders the added flexibility to run your code from ram, i.e., you can't run cpm on an AVR or a 8051 even if the instruction sets were all the same.

author: rstofer
author_rank: Super Contributor
timestamp: November 03, 2021, 09:05:20 pm
content: Use a Teensy 4.1 at 600 MHz and get some real speed. I have CP/M running on a 50 MHz eZ80 and it moves right along.

author: woofy
author_rank: Frequent Contributor
timestamp: November 03, 2021, 09:21:56 pm
content: Quote from: SiliconWizard on November 03, 2021, 07:52:56 pmMaybe, but that wouldn't work for me. When I recently decided to build myself a Z80 board to play with, the over-riding criteria was it had to have a real Z80, not an emulation or simulation. I also wanted wanted keyboard input and VGA output, but didn't want to mess around with a lot of TTL chips, so I mopped up all the random logic into an FPGA.But as you say, each to their own.

author: SiliconWizard
author_rank: Super Contributor
timestamp: November 03, 2021, 09:23:27 pm
content: Quote from: commie on November 03, 2021, 08:18:25 pmYou probably didn't quite get what I meant. The point was not to try and run CPM (or any vintage software) directly on another, modern target. You could not anyway, you'd have to port it first, and good luck. I was talking about emulation. My point was just, if you're going to emulate a number of digital ICs inside a modern MCU, why not go all the way, emulate the CPU as well, and be done with it, with a much smaller board in the end, and much faster.People interested in emulating Z80 (and others, such as the 6502!)-based systems entirely (or partly, you could just use a part of the following!) in software, I suggest having a look at the CHIPS project:https://github.com/floooh/chipsI evaluated it lately, and found it pretty good. It comes with a number of examples including a ZX Spectrum and C64, all fully working as far as I've tested.But this is just a thought. I reckon that developing "vintage" new projects is a thing in itself, and I admit there isn't just one right way of doing it. I guess everything goes, and it's entirely up to you!

author: commie
author_rank: Frequent Contributor
timestamp: November 03, 2021, 09:38:07 pm
content: Quote from: rstofer on November 03, 2021, 09:05:20 pmVery nice but a quick skip over to Mouser reveals eZ80 are only available in 100 pin lqfp packages, clearly not designed for people doing small time proto work, but hey, put an eZ80 in a pdil 64 package and I'll take one and play with it.I have also seen the Z180, which is available in 68plcc packages, not as good as the eZ80 but a bit closer to home.

author: commie
author_rank: Frequent Contributor
timestamp: November 03, 2021, 09:55:15 pm
content: Quote from: SiliconWizard on November 03, 2021, 09:23:27 pmI did get your original point, the problem with fpga's from my point of view is they are expensive and come in packages which are difficult to prototype and Vcc is usually <5V, this suggests the latest wiz silicon is not aimed at people like me.I like through hole components which I realize they are not in vogue, but I'm happy with that.

author: rstofer
author_rank: Super Contributor
timestamp: November 03, 2021, 10:36:03 pm
content: Quote from: commie on November 03, 2021, 09:38:07 pmI bought the chip on a board that included headers. I built an identical sized daughter card to hold a compact flash and a couple of FTDI chips to handle USB communications to the serial ports. Pretty simple...80F91 E-Net Module probably identical to:https://octopart.com/datasheet/ez80f915005modg-zilog-684179At the mainstream level, it seems like the board is obsolete. Bummer...I wouldn't even consider trying to make a PCB for such a thing, even at 64 pins. That, and why would I want to give up pins? It takes on the order of 24 pins just to drive the compact flash. I prefer to just plug a card into my project.

author: SiliconWizard
author_rank: Super Contributor
timestamp: November 03, 2021, 10:50:20 pm
content: Yep. Same answer for what the OP said regarding FPGAs, or more recent MCUs. Just buy dev boards. There are tons of them out there, many are cheap, with 0.1" headers, so you can plug them on your own PCBs as through-hole components. Unless you are willing to make a product with thousands a year, those boards are fine!

author: rstofer
author_rank: Super Contributor
timestamp: November 03, 2021, 10:53:26 pm
content: Quote from: SiliconWizard on November 03, 2021, 09:23:27 pmTo run Pac-Man requires a Z80 and a bunch of PROMS and RAMs in a particular memory map. Plus sound, of course and I want Pac-Man...My second FPGA project, following the mandatory 'blinking LED' project was bringing up CP/M based on the T80 core (at Opencores). After that, Pac-Man was easy.My next project was to implement an entire IBM1130 including emulations for the card reader, typewriter, keyboard, printer and disk system. Works well! I like Fortran...I would also point out the PiDP11 project that runs on a Raspberry Pi and is faster than the factory machine. It's kind of fun to work in pure Unix without all the extraneous gadgets.https://obsolescence.wixsite.com/obsolescence/pidp-11

author: Bassman59
author_rank: Super Contributor
timestamp: November 04, 2021, 12:13:06 am
content: Quote from: SiliconWizard on November 03, 2021, 07:52:56 pmWhile not a vintage CPU, in that spirit, I have a back-burner project to implement the famous Delta Lab Effectron II digital audio delay in a 500-series plug-in rack module.For those not familiar with this particular work of genius: it's a single channel delay with a maximum delay time of one second (actually 1024 ms). A bank of old EDO DRAM is used to implement the delay. A state machine/sequencer to drive the memory and implement the sampler is made from various 4000-series CMOS gates, counters and flip-flops. An RC oscillator and CD4528 VCO chip set the clock frequency which is varied by a pot. The clock runs from 250 kHz to 1 MHz.The company was called Delta Lab because the sampler used delta modulation. It is basically a textbook implementation of how you'd implement a one-bit oversampling converter out of MSI parts (4016 switches, 4013 flip-flops, 4015 shift registers, 311 comparators, TL082 op-amps).Here is the cool part: they don't bother to decimate the one-bit high-frequency conversion result down to multi-bit-wide but lower sample rate conversion result. Instead, they put that one bit result into the DRAM. At the output, they take the shifted one bit result and run it through an identical-to-the-sampler recovery circuit. The DRAM is basically one very long one-bit shift register. Coarse time delay is set by front-panel switches, with 16 ms, 64 ms, 256 ms and 1024 ms options. You get in-between delay times by changing the clock frequency! So you get fun things when you change the delay time when there is signal in the memory. There's also an infinite hold option, which simply takes the output of the shift register and feeds it right back into the input. An LFO wiggles the sample clock frequency for cool phasey effects.My idea, then, is to retain the idiosyncratic part of the design that makes it what it is: the discrete (well, MSI logic) implementation of the modulator and the VCO clocking. The memory can be implemented in block RAM in a small FPGA, and the rest of the control stuff can be done in the FPGA, too.So it's an emulator but retains the neat features, and fits into a form factor the studio people like.

author: SiliconWizard
author_rank: Super Contributor
timestamp: November 04, 2021, 01:05:28 am
content: Interesting! I implemented a 1-bit delta ADC and DAC with some logic and a comparator when I was studying. It fed a Z80 CPM computer and I implemented some basic digital sampler with it using assembly and Turbo Pascal! Fun times.

author: DiTBho
author_rank: Super Contributor
timestamp: November 04, 2021, 11:04:37 am
content: Quote from: SiliconWizard on November 03, 2021, 09:23:27 pmPrecisely. It makes more sense for me.

author: DiTBho
author_rank: Super Contributor
timestamp: November 04, 2021, 11:16:04 am
content: CP/M ... I don't like it at all.Its filesystem doesn't support folders, you end up with files all messed up in the same root, I wouldn't use it even if I was paid.I am only happy with things where you don't have an OS, just a loader, you write things in assembly on the host, you download to the target, and play with the hardware.

author: Yansi
author_rank: Super Contributor
timestamp: November 04, 2021, 11:18:16 am
content: Quote from: commie on November 03, 2021, 08:18:25 pmYou can make 8051 easily to work as a von Neumann. Just wire together XCODE and XDATA into the same physical memory.

author: DiTBho
author_rank: Super Contributor
timestamp: November 04, 2021, 11:29:00 am
content: Quote from: Yansi on November 04, 2021, 11:18:16 amYup! There are tricks!Dallas Semiconductor did that in a couple of commercial products using their "51 on steroid" CPU.Imagine a CPU similar to the 51, compatible with 99% ISA, but with a clock of 50 Mhz.( the C compiler "sdcc" still has support for their "ds390" "ds400" )This stuff in 2004 was able to emulate z80 programs and even a picoJava virtual machine.

author: woofy
author_rank: Frequent Contributor
timestamp: November 04, 2021, 12:44:19 pm
content: Yep, wonderful chips back in the day. I used an earlier version, the DS87C320, in a motion control system.They ran at 33MHz instead of the 8051 12MHz, and only 4 clks/cycle instead of 12.

author: commie
author_rank: Frequent Contributor
timestamp: November 04, 2021, 02:50:27 pm
content: Quote from: Yansi on November 04, 2021, 11:18:16 amYou are certainly correct but if you take a look at the 8051 instruction set then it is clear that it was originally designed for small specific jobs, above the first 255 bytes of xram the programmer has to invoke itssingle16 bit pointer, if I use xdata above the first 255 bytes then my compiler bloats like hell. Yes, I know Atmel has made significant enhancements in this area but many 8051 compilers don't support these dual pointer enhancements.Clearly, the 8051 was designed for small products such as shortwave receivers used to control the synthesizer, pH metering etc, then the 8051 is a perfect fit.However, consider a scientific calculator and the Z80 becomes the ideal choice, hence ti83+, ti84+ etc

author: rstofer
author_rank: Super Contributor
timestamp: November 04, 2021, 03:52:53 pm
content: Quote from: DiTBho on November 04, 2021, 11:16:04 amYou have a point but with only 242 kB of storage on an 8" floppy, there weren't going to be all that many files. With larger disks later on, adding extra drive letters became workable and I usually had all 16 possible drives. Pascal went in the P: drive, C went to the C: drive and Fortran went to the F: drive. I had a collision with the PL/I stuff.Two drives made things much more workable. The A: drive for utilities, the B: drive for the project files. We didn't have virtual garbage cans, the idea of multiple millions of files in thousands of directories didn't come along until much later.I was just happy to get away from the paper tape and audio tape schemes. It was truly a PITA and not very professional.We were darn lucky to have such a small OS for the 8080s back in the early days. Only the wealthy had 64k of RAM in the early days and, when initially built up with 2102 RAM chips, the box became an excellent heater. It wasn't until MUCH later that a 64kx8 CMOS RAM chip became available.Those were great years but, fortunately, they are behind us. We've come a long way since the Altair 8800 was introduced in late 1974 and became the cover story of Popular Electronics in January 1975. I started grad school in the summer of 1975 concentrating on hardware design. I really wanted to know more about microcomputers. It has been a 'bleeding edge' experience ever since.

author: DiTBho
author_rank: Super Contributor
timestamp: November 04, 2021, 05:46:59 pm
content: my old pocket SHARP BASIC calculator (1992) has 32Kbyte of of disk. It's smaller than a 8" disk, and it's static ram with a battery in a cartridge. The firmware of the z80-calculator is basically a "Basic interpreter" also able to loads and executes binaries, and implements a true filesystem with folders.You have 11 chars for the folder-name and 8+3 chars for the file-name; pretty like with DOS, but you can only have 4 levels of deepness:folder1/subfolder2/subsubfolder3/subsubsubfolder4It's nice to organize matrices, Basic programs in categories, assembly files, assembly binaries, lists, graph-tables, etc.-CP/M in 2021 is really annoying for my tastes, I do find it frustrating, especially when I tried to use an old C compiler to compile something useful, and to be honest, it is more annoying then the ACORN filesystem that doesn't support any file-extension, so if you have lib_module.c and lib_module.h, you have to- create folder "C"- create folder "H"- rename "lib_module.c" as "C/lib_module- rename "lib_module.h" as "H/lib_module- adapt Makefile accordinglywhich was so really annoying for me that a couple of years ago I created a tool that automatically adapt files from "UNIX" to "ACORN" and vice-versa.

author: PKTKS
author_rank: Super Contributor
timestamp: November 07, 2021, 11:41:08 am
content: Quote from: DiTBho on November 04, 2021, 11:16:04 amNot like this.CP/M at the time - there was no standard "filesystem"there was not even a standard format to move a file from one CP/M to another.But while using a single CP/M installation you can:= SELECT ONE in 16 "DISK" (from A to P) as if is a working "folder"= SELECT inside thatdevicea USER area from 0 to 15 as if is asubfolderThe relevant CP/M command tosubfolderis: USER xThese concepts pre dates modern filesystems and folder structs.Rather very expensive hardware was needed to do thisPaul

author: SiliconWizard
author_rank: Super Contributor
timestamp: November 07, 2021, 06:27:12 pm
content: Quote from: DiTBho on November 04, 2021, 11:29:00 amThis actually was/is a very common setup for many 8051-based systems. Nothing special.

author: bson
author_rank: Unknown
timestamp: November 08, 2021, 12:18:10 am
content: Quote from: PKTKS on November 07, 2021, 11:41:08 amAh yes, I had forgot all about using kermit to transfer files between systems...

author: westfw
author_rank: Super Contributor
timestamp: November 08, 2021, 01:25:35 am
content: QuoteIIRC, the CP/M "File System" was a lot more standardized than floppy formats of the day. Especially 5inch floppy formats; I purchased a number of CP/M products on 8inch floppys that were pretty much expected to be readable on any CP/M system with an 8inch drive. (OTOH, that might have been because they had their own BDOS in a boot sector or something...)

author: rstofer
author_rank: Super Contributor
timestamp: November 10, 2021, 10:46:14 pm
content: Quote from: bson on November 08, 2021, 12:18:10 amI forgot how I did it but you can imagine the problem of getting CP/M from a machine with an 8" Floppy onto an FPGA incantation with a Compact Flash. Kermit was definitely involved in the later stages.Actually, using something like Linux' dd command might have been a great help. I have used that approach with later projects.

author: ale500
author_rank: Frequent Contributor
timestamp: November 15, 2021, 03:41:16 pm
content: CP/M disks have 128 byte sectors, if one could write its own BDOS, why nobody is using 512 byte sectors (I mean nowadays that compact flash and SD cards are the choice) ? I haven't read enough about CP/M yet, maybe the answer is very obvious, and in front of me....