Building an Atari ST
This is the first article of a series I am writing about a home project I started in late 2019 : implementing an Atari ST on a FPGA board.
I have been a programming enthusiast since quite some time now. I have been programming many kinds of old, modern computers and anything in-between, but to me the most enthusiastic times where when I was programming on the Atari ST and Falcon computers, mostly demo effects and tools, but also desktop utilities. In the recent years I have mostly been focusing my projects towards the Atari ST, as it still is the machine I have fun hacking on.
When starting new projects I like to do stuff I have never done before, and I seldom (if not never) reuse the same pieces of code. I also did quite a bunch of Atari-ST demoscene-related stuff, like hicolor image encoding with MPP and some experiments on anaglyphic stereoscopic 3D. In the first half of 2019, after the release of "We accidentally your Oculus", I have been in a non-productive mood, with a lack of inspiration about anything new to do on ST machines.
Besides being a software programmer, I also have basic knowledge in electronics, thanks to my degree studies, and more recently, in 2017 I had a one week training session on FPGA programming. It was using Xilinx chips programmed in the VHDL hardware design language.
Since I was not inspired in starting a new software project, and I wanted to practice and improve my skills in VHDL and hardware design, I decided to start a hardware project. Also, I wanted a project that is challenging and motivating enough. I could not find a better idea than trying to re-implement the dream machine, the Atari ST!
If you do not know what a FPGA is, just consider it is a chip that contains a lot of configurable logic, fast memory (although limited in size) and arithmetic blocks. The interconnection between those blocks is configurable too, so you can implement any logic function, state machine or anything you would have done using classical logic chips and wires. The difference is that instead of a soldering iron, you use a computer to describe your logic design in a specific hardware description language, namely Verilog or VHDL. Those languages are the very same that are used for designing modern processor architectures, and FPGAs are typically used for early prototyping new processor designs. So you really can consider FPGA programming as hardware development. This has nothing to do with software emulation: emulators are software programs that implement some kind of hardware environements as accurately as possible, while on a FPGA you directly have the hardware. On a FPGA, you can replicate some hardware that is identical to the original to the transistor level, even if you generally don't need to, as you only want it to behave the same as the original, regardless on how it is implemented internally. A typical software emulator will put more stress on the CPU when more accuracy is required. There is no such notion of "CPU load" on a FPGA. The limit is more about the quantity of logic resources you want to use compared to those available on the FPGA.
I am perfectly aware that there already are hardware implementations of the Atari ST available, even as open source. My project is more for me to gain experience on how to build a computer on top of an existing FPGA-based platform, using only the same standard components than those that were available when the Atari engineers started to create the ST. So I chose not to inspire from those open source projects, not even reading any piece of source code, and do everything my own way. One of those projects, FX CAST, a MiSTer core by Jorge Cwik aka Ijor, even has achieved perfect cycle accuracy. So I’m really not doing this work as a concurrent but more like as a weekend hobbyist having fun with FPGAs. If you want hardcore cycle accurate stuff, get a MiSTer and use FX CAST. However, I do plan to achieve quite an accurate reproduction of the ST hardware, so in the end it could get close to cycle accuracy, but I am making no promises.
As I already had experience with Xilinx FPGAs, I wanted the board for my project to feature such a chip. Also, while I wanted to emulate the internals of the ST, I did not want to provide hardware compatibility with the ancient peripherals like the good old Atari mouse, joysticks, serial and parallel ports, scart monitors etc. I just don’t need them. I do not own a CRT monitor nor a matrix ribbon printer anymore. The peripherals I want to use are USB keyboards, mice, game controllers, and HDMI screens. So I needed a board with all the necessary controllers and connectors, and a CPU to run drivers for USB devices and provide some emulation such that the implemented ST "sees" a real ST mouse, a real ST keyboard etc. The cheapest board I could find is the MYIR Z-Turn board, which is a small board featuring the Xilinx Zynq chip, containing both FPGA programmable logic and two ARM cores that can run Linux, one gigabyte of DDR3 memory, a HDMI display controller that can be directly handled by the FPGA logic, USB, Ethernet, a SD-card drive, everything I needed, with official prices varying from $99 to $119, depending from the used version of the Zynq chip. So I bought the version with the Zynq 7020 chip, the one with the most FPGA resources available. This board is relatively feature-similar with the DE10-nano board, which forms the basis of the MiSTer project. The main difference is the DE10-nano features a FPGA from Altera (now Intel) and I am not familiar with those, and the associated development tools.
One of the major components I based my project on is fx68k, the open source core by Ijor. It is a cycle-exact implementation of the Motorola 68000 processor that he uses as the basis of his FX CAST core. Using it is exactly like working with the real thing, just like the Atari engineers building the ST around the 68000 chip. This is the most important part as it has access, directly or indirectly to every other chip of the machine. Another open source core I used is for the ACIAs, two chips which enable serial communication, one for the MIDI ports, and the other for the internal serial link between the mainboard and the keyboard processor. A last open source core I used is for the keyboard processor itself, the Hitachi HD6301 microcontroller. All the rest is implemented by myself.
I also based my project on the available schematics of the ST that can be found on the web. I try to stay as close as possible to the schematics in my design. So it mostly features the same chips, with the same pins, and the same signals between chips. For the off-the-shelf chips that the Atari enginers used in the ST design, the freely-available datasheets were very useful to make a re-implementation possible. However, for the custom chips specifically created for the ST (namely : the GLUE, MMU, Shifter and DMA chips), I mostly had to make a guess on how they worked. The best indices I had were their pins, determining which information the chips had access to, and also which information the chips had not access to, which determine what the chip may be able to do and what it can not do. For MMU and Shifter, they are in a rather finished status, even though there might remain some bugs that need fixing. GLUE is partly implemented, but some parts are still missing because I haven’t implemented yet some ST functionalities. DMA is currently an empty shell, as I have not implemented the storage devices it controls yet. The general idea on how I designed those custom chips is by trying to implement each of the functionalities in the simplest possible way. I guess by doing this I get as close as I can to the real way those things work. The Atari engineers would probably have done the same or similar way, to minimize the required logic.
So, I have started the zeST project. You can watch its progress by following the project page on github. The source code is distributed under the GPLv3 free software license. Currently, the working parts are :
- the bus, with full integration of che cpu, mmu and memory implemented using the onboard DDR memory
- the video output, with integrated specific scan doubler to enable the display of the PAL/NTSC outputs on HDMI monitors
- a complete implementation of the Atari keyboard, including the onboard HD6301 microcontroller, also controlling the mouse and joysticks
What is currently not working are storage devices (floppy, hard disk) and sound. Some external IO do not and will not be implemented (serial, parallel ports). MIDI might be implemented using USB adapters, but a bit of investigation is still required.
That's all for the introduction of this series! In the next articles I will focus on different parts of the project, what were the ideas behind the implementation of this or that feature. Stay tuned, see you soon!