Stephen Smith's Blog

Musings on Machine Learning…

Archive for the ‘fpga’ Category

Continuing the MiSTer Journey

leave a comment »

Introduction

Last time, we started our MiSTer journey and could run the various cores that didn’t require the add-on memory expansion module. I finally received the memory expansion board, so now theoretically I can run any of the MiSTer computers, consoles and arcade games. For game consoles, this seems to be the case as all you need is the software images from the original game cartridges, for computers it’s a bit more complicated.

MiSTer uses the FPGA to replicate the original computer hardware. This leaves out the software side of things. Typically, you then need the boot ROMs and operating system. Once you can boot the operating system, then you can run various programs such as games.

Further, many of these older systems are rather quirky and you have to spend a bit of time learning the system. First a quick recap of components I purchased and components I already had lying around.

Quick Recap

I have quite a few Raspberry Pi type Single Board Computers, so I generally already have a number of the components for these sorts of projects, so here is a summary.

Components I purchased:

Components I already had:

  • HDMI Monitor
  • HDMI Cable
  • USB Keyboard
  • USB Mouse
  • USB Nintendo Game Controller
  • 128GB microSD card (plus USB adapter to plug into a computer)
  • microUSB cord and plugin, for power to USB hub

Nintendo – The Easy Part

Copy the files from the Arcade Punks image for Nintendo, namely games/NES and games/SNES and you are ready to play pretty much any Nintendo or Super Nintendo game. Already having an USB Nintendo game controller is a big help as you don’t need to worry about mapping buttons, etc. With these, loading and running the games is pretty painless. You just need to remember F12 is the MiSTer button to bring up the menu where you load them.

Atari ST – A Bit More Work

I copied the games/AtariST folder from the Arcade Punks image to the microSD card, inserted it into the DE-10 Nano, booted and chose Computers / AtariST from the MiSTer menu. I then received a blank screen. Popping up the configuration menu and selecting a floppy drive didn’t help. A bit of Googling revealed I was missing the GEM operating system. Atari referred to this as TOS (The Operating System) and you need this. AtariMania seems to be a good place to get a copy of TOS. Choose the version and language you prefer and download. I chose 2.06 and US English. Then copy the .img file to games/AtariST and rename it TOS.img. Now when you boot, you should load into the GEM desktop.

Once you have the GEM desktop running, then you can press F12 to select floppy disk images. Some of the images you can open and run the program contained on the disk. Others you have to select reset to cause a reboots since they are bootable floppies. For instance, here is Apache running.

As long as you aren’t too picky this is fine, meaning try a game, and if it doesn’t work properly then ignore it and run another, after all there are lots to choose from. There is a bit of extra complexity being glossed over here. Generally if you want to run a specific game, there may be a bit more work to do. Here is a list of potential issues:

  1. Hardware version. There were quite a few versions of hardware with different memory and processors. A particular game may require a specific hardware configuration from the MiSTer configuration.
  2. TOS software version. A particular program may require an exact version of the TOS image. It may not work on either newer or older images.
  3. Many of the games were on copy protected floppy disks, these are mostly available in “cracked” versions meaning the copy protection has been removed. This process might have introduced bugs, hard to say the quality of any specific “crack”.
  4. Perhaps there is a bug in MiSTer? Completely modeling a computer as sophisticated as an Atari ST is a challenge. They seem to have done a great job, but bugs are still being fixed and functionality improved.

A key thing I found is patience. Loading some of these old games is slow and as I’m about to give up, suddenly it appears or starts. MiSTer claims to emulate the speed of the CPU exactly, but I’m not sure about floppy disks. They do seem slow, but then I don’t know if it’s the CPU running at 8MHz, the 1MB RAM or the slow floppy drive.

Summary

With each step I can run more things on my MiSTer system. Some are easy to get going. Others require patience. The MiSTer name was formed out of the Mi in Commodore Amiga and the ST in Atari ST. So I have the Atari ST part working. Now onto the Commodore Amiga which looks fun.

Written by smist08

June 14, 2024 at 12:11 pm

Getting Started with MiSTer

with one comment

Introduction

Imagine you could have a small Single Board Computer (SBC) with programmable hardware that can be configured to run as any personal computer, gaming console or arcade machine created before 1990 or so? This is what the ambitious MiSTer project sets out to do and largely accomplished. The project is mainly driven by gaming enthusiasts who want more accurate game play than running in a software emulator, but these systems can run any software these PCs run. I first encountered MiSTer when I purchased a Sipeed Tang Primer 25K FPGA to play with creating RISC-V cores in System Verilog. However, one of the fun things the Tang Primer does, is run a ported version of both the MiSTer SNES and NES systems.

I then attended a session on MiSTer at LinuxFest Northwest and was completely blown away with how much MiSTer has accomplished. Scott Dowdle gave a great session and showed several MiSTer systems in action. He made everything look easy and I looked to set up a working MiSTer system of my own. However it is quite a DIY process. You can buy a complete system, but availability seems to be limited and they are quite expensive. This blog post covers the start of my MiSTer journey.

First Step – Buy the Hardware

The official MiSTer FPGA board is the Terasic DE10-Nano Kit. There are ports of parts of the MiSTer system to other boards, but if you want to run everything this is the board to get. Scott Dowdle recommended buying this directly from Terasic, but being Canadian, this gave me a terrible exchange rate and expensive shipping. I found it better to buy from Digikey Canada where I got a much better deal all around, including free shipping via FedEx.

With this board alone, you can run some of the simple systems such as the Apple II, however you can’t run anything much newer such as the Atari ST or Commodore Amiga. For these you need a memory expansion board. I ordered one from MiSTer Addons. The problem here is that they seem to have discovered the worst shipping company in the world, namely GlobalPost, who have spent two weeks moving the package from Idaho to LA, CA. Now they’ve given it to the US Postal service. If MiSTer Addons had just shipped by regular post, it would have been way faster and cheaper. I still don’t have the memory expansion board, but at least I can run a few simpler systems.

Second Step – Install Software (and buy more hardware)

The DE-10 runs MiSTer from a microSD memory card. To install MiSTer on the microSD card, you burn an image from Mr. Fusion which installs a minimal image, and after rebooting will download more from the Internet.

Doing this from a Windows PC is a pain because, without extra software, Windows can’t read Linux file systems and MiSTer uses a small Linux kernel to control everything. If you burn Mr. Fusion on Windows, then after burning the card isn’t readable and fails the verify step. I found dealing with the MiSTer microSD card from MacOS way better as everything just works.

After you burn the microSD card, you boot the DE-10, it comes up with the menu. To configure the system further you need to connect a keyboard to a USB port. Usually an easy thing, but not here.

The DE-10 doesn’t have standard USB-A or C ports. Instead it has microUSB ports (two different types) and comes with cables to connect these to your computer, to allow you to program the FPGA. The problem then is that this results in a male USB connector and keyboards have male USB connectors. Hence you need either a female to female adaptor or as recommended a USB hub that connects to the correct microUSB port type. Fortunately you can order a reasonable hub from Amazon for $13.00. You can order a better USB hub from Mister Addons, but theirs is $80USD and the shipping seems to take a month. Anyway the hub from Amazon arrived in a couple of days and works fine. Note that it is required to be powered, the DE-10 doesn’t have enough power.

Once the keyboard is connected, you can configure WiFi. The DE-10 doesn’t have built-in Wifi, so you need a USB Wifi dongle. The one I have wasn’t recognized. I could connect an ethernet cable, but then I would have to move everything upstairs. Instead I found the MiSTer Downloader PC Launcher which lets you update the microSD card from your laptop. Again, I needed to use a MacBook as it has no problems with dealing with Linux file systems. This step adds all the MiSTer engines. Basically, the System Verilog code to reproduce the desired computers, but without any software to run.

One way to get lots of software is to download the Arcade Punks 1TB MiSTer image. It took a couple of days to download this. I only have 512Gb drives in my laptops, but do have a 5TB external drive, so I could download to that. Then it took 8 hours to decompress the file. Then I could mount it on the MacBook (by double clicking on it) and access the files. The biggest microSD cards I have are 128Gig, so I just copied a few files from the Arcade Punks image to play with.

Actually Playing Games

Without the memory expansion board, I can only run a few 8 bit systems. I played with the Apple II and the Atari 5200. With these I could play a number of classic games. I don’t know how to take screenshots with MiSTer, so I took photos of the monitor with my phone. Back in the day I owned an Apple II+, so I remember playing many of these games back in the day.

Castle Wolfenstein on the Apple II.
Zaxon on the Atari 5200.
Galaxians on the Apple II.

Summary

MiSTer is a lot of fun to play with. But it is DIY and takes a bit of patience to get working. The community is great, so you can get help online. I started with this article without the memory expansion board, since I figured it would be long enough. I look forward to moving on to some of the new systems like the Amiga and Atari ST in the weeks ahead.

Written by smist08

June 7, 2024 at 1:43 pm

Posted in fpga, gaming

Tagged with , , ,

Meet the Sipeed Tang Primer 25K FPGA

with 2 comments

Introduction

Last year, I got interested in FPGAs and purchased a Digilent Basys3, which was lots of fun to play with, I even got a minimal RISC-V processor programmed. The Basys3 is their lower end board and doesn’t have any RAM, limiting what you can do, since it has to use logic elements such as flip-flops to fulfill this purpose. To go further, I saw I could get the Sipeed Tang Primer 25K, inexpensively, containing many more logic elements along with RAM. This board is based on the Gowin 25K Arora FPGA and as such means learning the Gowin development tools rather than the familiar AMD Xilinx Vivado tools. This blog post is a review and some of my experiences using this board, including going down the rabbit hole of FPGA retro gaming.

Initial Setup

I received the Tang Primer 25K FPGA gamer bundle, which included a pair of Playstation compatible controllers that attach to a PMOD to connect to the board. However, this isn’t complete, you still require TFcard, HDMI and RAM PMODs which I needed to order separately. Would have been nice if the gaming bundle included everything required. Note that you need to use the Sipeed PMODs as others such as those from Digilent often are wired up differently. Ordering the collection, gives you a few other things to play with such as LED displays and pushbuttons.

The AMD Vivado development tools are really well documented with lots of tutorials and examples. Sipeed provides a wiki for their products and Gowin provides quite a bit of documentation, but the quality isn’t there and many of the instructions are incorrect. For instance, Sipeed says to use their special copy of the programmer to download programs to the FPGA rather than the Gowin one. However the special one didn’t work for me and I found the latest Gowin one was the correct one to use. It was nice that I could just download what I needed without requiring any interactions with Gowin, no export restrictions, since these are all Chinese companies.

FPGA Retro-Gaming

I previously looked at retro-gaming on the Raspberry Pi where people have written emulators for all sorts of processors and gaming systems. Now there is a new project MiSTer FPGA which emulates the hardware of various gaming consoles for FPGAs. I used the snestang fork which emulates the super-nintendo on various Sipeed Gowin based boards.

I didn’t have much luck initially, since I couldn’t load any games from the SDCard, but with some help from the developer, they made some changes to allow a bit more tolerance in accepting different cards. With that, I could load games, but had trouble starting them. Turns out you need to hit the start button first, hitting random buttons seems to disable the controller to the game.

Anyway, with that I could play games. The Verilog code that implements the Super Nintendo system implements a 65C816 cpu which is a 16-bit version of the 6502. This CPU was also used in Apple’s short-lived IIgs. Besides this CPU, it implements a RISC-V CPU that is used to provide the menu for system options and to choose the game to load, which it then loads from the SDCard. This gives you a basic RISC-V CPU with minimal firmware, HDMI support, SDCard support, controller support along with a menuing system.

This isn’t a bad starting point for playing with RISC-V hardware definitions. It gives you plenty of devices to play with, plus a debugging framework where you can print back to the host computer through the usb port, which can be read by putty.

Summary

The Tang Primer 25K is quite a powerful and capable FPGA at a reasonable price. You really need to get the pack of all the Sipeed PMODs so you have some devices to play with. I found it takes some patience to work with the Gowin tools and for me, with the 25K being fairly new, a lot of the documentation hasn’t kept up. You really rely on the samples to see how devices are connected, so you know how to map them in your program.

I think the FPGA approach to recreating vintage video game hardware is really cool. I just hope this doesn’t get stomped on by companies like Nintendo, who have a history of stepping on people’s fun.

Written by smist08

April 1, 2024 at 6:45 pm

Posted in fpga, RiscV

Tagged with , , , , ,