newb question - Page 1
Forum section: electronics / general

author: vivi-d
author_rank: Regular Contributor
timestamp: July 18, 2022, 07:27:22 pm
content: I was wondering if you could help me understand more about FPGA development...Suppose someone wanted to recreate newerish video game console, is it enough to just describe the instruction set in VHDL to recreate a processor. Or is there more involved that I haven't learned of yet?

author: pbernardi
author_rank: Contributor
timestamp: July 18, 2022, 08:12:46 pm
content: Hello,Theoretically you could describe a instruction set and make a processor using HDL language. But the behavior of this processor have some real-life limitations:1) The target processor you described have to fit in the logic you have in the FPGA (FPGA does not have infinite logic and because it is programmable, with predefined cells, it will waste more logic than a fully customized ASIC)2) The FPGA has speed limits (IOs, general logic, DSP, BRAM, etc.). Usually you can find these limits at target datasheet.As the result of 1) and 2), if you implement a processor which fits an FPGA, the odds are you implement a much slower processor than a "newerish video game console", *if* you describe the processor flawlessly (which is a very difficult task).Moreover, the processor is only one of several necessary parts of console. You need also some kind of ROM storage (one SSD, HDD, disk for older consoles, or even cartridges), and a volatile memory (SDRAM or some of several kinds of DDR{1/2/3/4} modules). Memories, in general, are prebuild in FPGA and divided in small BRAM modules, so you cannot have as much memory you want. Usually, you can have enough memory for cache in a FPGA and that is it.So, once you cannot embed memory, you have to think at least on some kind of flash/ram controller + caches added to the processor. (+ interfaces with keyboard, control, power supply, etc.). All this put, the effort to develop this from scratch is *huge*.

author: langwadt
author_rank: Super Contributor
timestamp: July 18, 2022, 08:36:28 pm
content: Quote from: pbernardi on July 18, 2022, 08:12:46 pmand once you have done that you miss the parts that most people never get to; development tools so you can actually make something with that fancy new CPU you just made

author: pbernardi
author_rank: Contributor
timestamp: July 18, 2022, 09:17:20 pm
content: Well, vivi-d stated in his case about an existing instruction set, so I suppose in this case the processor would have at least some kind of support.But for a new instruction set, yes, there is no development tools for CPU with non-standard instruction set.

author: Someone
author_rank: Super Contributor
timestamp: July 18, 2022, 11:07:52 pm
content: Current state of the art:https://github.com/MiSTer-devel/PSX_MiSTerGood luck implementing a CPU and/or GPU and/or DSP, they aren't always fully documented!

author: vivi-d
author_rank: Regular Contributor
timestamp: July 19, 2022, 12:10:37 pm
content: QuoteIs the difficulty of describing a processor flawlessly due to not having the right docs? Is there more than knowing the instruction set and how many clock cycles each instruction takes?

author: pcprogrammer
author_rank: Super Contributor
timestamp: July 19, 2022, 01:18:03 pm
content: A processor is more than just the instruction set.1) There is the ALU2) There are the registers3) Stack mechanism4) Instruction pointer and instruction fetch mechanism5) Instruction decoding6) etc.And that is just a simple processor. For the more complicated ones there is memory management, pipelines, caches.If you are thinking about such an operation from scratch it might be an idea to first write an emulator on a computer to get an understanding of the instructions and workings of this processor you have in mind.Edit: Take a look here:https://www.tutorialspoint.com/microprocessor/microprocessor_quick_guide.htm

author: vivi-d
author_rank: Regular Contributor
timestamp: July 19, 2022, 02:21:34 pm
content: Thanks for the link! I'm starting to appreciate the complexity lol

author: rstofer
author_rank: Super Contributor
timestamp: July 19, 2022, 03:18:52 pm
content: As a learning project, there is the LC3 processor from Patt & Patelhttps://www.amazon.com/Introduction-Computing-Systems-Gates-Beyond/dp/0072467509It's a simple RISC type processor of somewhat limited capacity but it's a great start. The project is laid out for microcoding and a worksheet is provided. I used the Finite State Machine without microcoding approach but there's nothing wrong with microcoding. In some ways, it is easier.Figure C.2 gives you just about all you need to know to write the VHDL code:Figure C.3 gives the hardware layouthttp://users.ece.utexas.edu/~patt/05f.360N/handouts/360n.appC.pdfAppendix A provides info on the instruction sethttps://www.cs.colostate.edu/~cs270/.Summer22/resources/PattPatelAppA.pdfThis project is used by a lot of universities as part of the hardware design program. Info is all over the Internet. And, yes, there is an assembler. It easily runs at 100 MHz on a Xilinx Artix 7 and can probably run at 200 MHz with a little effort. But that's SLOW compared to a Teensy 4.1 at 600 MHz and a really fast design.https://www.pjrc.com/store/teensy41.htmlThere's a pretty good intro to CPU design in this project. Figure the main file (I called it LC3.vhd) for around 1000 lines of code. There are several components that add a few hundred lines (UART, BlockRAM, etc. See attached file explorer page).

author: pbernardi
author_rank: Contributor
timestamp: July 19, 2022, 03:21:19 pm
content: Quote from: vivi-d on July 19, 2022, 12:10:37 pmLack of documentation is of course a factor. In the end, I think it depends really on what instruction set you are going to try. RISCV for example, is a FPGA-friendly ISA (https://www.hackster.io/news/the-rise-of-the-dark-risc-v-ddb49764f392presents an implementation in one night!)Some other processor just have too many instructions to decode or are too irregular (CISC processors with different instruction cycles, long pipelining, etc.). In the end, I think, describing a simple, not optimized processor with a simple ISA is not an big issue. But if you want to describe an complete processor to work fast and efficiently, this is a challenge.To give you an idea: most soft cores works at 100-200MHz range at best. For low-ends FPGAs, it is not uncommon to find processor implementations working at speeds <100 MHz.You might take a look at some soft cores to have an idea. There are some references:- Opencores:https://opencores.org/- There is a thread here about RISCV:https://www.eevblog.com/forum/fpga/the-neorv32-risc-v-processor/- You can look at some old processors which are now open source: J-core or PowerPC for example.

author: rstofer
author_rank: Super Contributor
timestamp: July 19, 2022, 05:27:08 pm
content: PACMAN!There is a Z80 core ( named T80) at OpenCores.org that can be modified slightly to play PACMAN using the ROMS from the MAME PC implementation.https://opencores.org/projects/t80https://www.fpgaarcade.com/kb/pacman/I realize that this is nothing like a modern game console but installed in a cocktail table, it is kind of cool. You can buy one prebuilt or, if you like woodworking, build your own. There are plans on the Internethttps://www.henningludvigsen.com/index.php/2020/12/23/building-a-cocktail-arcade/There are also some Raspberry Pi game emulations around.I also added a compact flash to that T80 core and installed CP/M 2.0 - worked very well. Hint: Watch that Interrupt line, it floats high and that causes a recursive interrupt. You need to get control of the signal.

author: james_s
author_rank: Super Contributor
timestamp: July 19, 2022, 05:58:03 pm
content: I learned a lot by porting MikeJ's PacMan implementation to various FGPA boards. His projects are very well done and typically work very nicely.

author: ejeffrey
author_rank: Super Contributor
timestamp: July 19, 2022, 06:19:34 pm
content: You can make soft processors for a variety of instruction sets in an FPGA, and do so fast enough to emulate older gaming systems but not modern consoles.That is only the start of what is needed as the CPU is only one part of a gaming console. A lot of it also depends on how accurate you want to be. For an in-depth look at what it takes to fully emulate all aspects of the hardware (CPU, video and audio processors, and other peripherals) of a 30 year old gaming console check out:https://arstechnica.com/gaming/2021/06/how-snes-emulators-got-a-few-pixels-from-complete-perfection/but also realize that functional SNES emulators that could play most games but did not provide pixel/cycle accurate behavior were already widely available in the late 90s.

author: james_s
author_rank: Super Contributor
timestamp: July 19, 2022, 07:54:57 pm
content: It takes a fairly large FPGA just to emulate the humble NES and it was quite a few years before that was well implemented so that puts things into perspective. FPGAs are a lot of fun for recreating vintage hardware but even that can be a big project. I've done several bronze age arcade games and it was not easy to get those working and I didn't even create the CPU for them, I used the existing T65 core.