Nuked-MD-FPGA – Emulating Sega Mega Drive chipset using decapped chips photos
github.com
github.com
I'm curious if there are any specific shortcomings with modern Genesis/Megadrive emulation that spurred this, or if this is just a pure "for the love of the pursuit" effort.
I'm not sure of the exact state of the art, but I know that getting sound emulation perfectly right for the Genesis/MegaDrive has been a tricky issue over the years, even for Sega themselves. Though, my (loose) understanding is that the issue is moreso with getting the analog bits sounding right rather than the digital bits.
In other words, they are not emulating the 68K, VDP, and other supporting chips on a gate-for-gate basis. They are emulating them at a higher level.
With the decapping of the Genesis' hardware, it should now be possible to truly emulate them at a 1:1 hardware level. This theoretically can lead to far more accurate emulation. I believe this is a lot more FPGA resource-intensive and may exceed what the existing MISTer/Analogue cores can handle, though I'm way out of my depth here.
I would definitely be curious to know why - the emulation of Genesis is notably behind most other video game consoles but I always assumed this was because of less interest and not because of any unique technical challenges.
hit a wall
Is there somewhere you'd recommend where I can read about the unsolved challenges of Genesis/Megadrive emulation?- Work RAM refresh timing seems to be a bit variable and the exact logic for the timing has been unclear
- The exact point when scroll values are latched from the internal scroll RAM when in full screen scroll mode is unknown
- Precise cause of a CPU lockup when configuring a 68K->VDP DMA and then performing a normal access instead is also unknown
- Certain details of sprite rendering that can show up in certain edge cases are also a bit unclear
- The function of some of the VDP debug registers is unknown
There's a lot more like that, but that hopefully gives you the gist. Nuked-MD-FPGA (and its C-based predecessor) will hopefully make a lot of those questions easier to answer since Verilog/C with a lot of unclear signal names is still a lot more easier to interpret than a die photo.
I looked but couldn't find much information on remaining games that still have emulation issues. This was about all I found: https://ares-emu.net/compatibility/21?status=3000
Last I looked into it, even Overdrive 2 was emulated pretty well...
> This was about all I found: https://ares-emu.net/compatibility/21?status=3000
IIRC this game shipped with broken EEPROM code so it's a bit unclear if this is actually emulated incorrectly. Ares is really in great shape these days
I do have a couple minor open compat bugs in BlastEm (my public issue tracker is sadly not up to date...), but I believe these are just normal bugs and not "we don't understand how this actually works" kind of things.
EDIT: > Last I looked into it, even Overdrive 2 was emulated pretty well...
Yes. In BlastEm there's a one-line glitch in one of the scenes I haven't managed to figure out. In Ares, there's a single effect that doesn't work (border dissolve after the "arcade" scene) and a 1-line glitch in the arcade scene. Both are only visible if you have overscan enabled.
(From memory: they sourced a variant of the sound chip with digital output, characterized the DAC that way, then built a test suite to compare emulator behavior with a real chip)
I guess it sort of depends on what you mean, but I don't think there are dramatic differences in emulation quality between the Genesis and other consoles of its generation. Admittedly, I am rather biased since I'm the author of one of those, but I think outside the add-ons Genesis emulation is in pretty good shape overall. Both Ares and BlastEm acquit themselves well on the most demanding demoscene prod[0] for the system and even Genesis Plus GX is fairly accurate for a more performance-focused emulator.
Now none of those are perfect and I think it would probably be fair to say that they are less-perfect than Higan is/was for the SNES (though it wasn't perfect either), but I don't think the delta is huge.
Now once you add the Sega CD and 32X things are definitely worse, but those combined systems are considerably more complicated to emulate than any of the base consoles of that era while also being much less popular.
Not sure where you are getting this from but I think that's far from true.
For years we had Kega Fusion which was able to run most (if not all) commercial games without any issues and was the pioneer of accurate Genesis sound emulation.
Then we have had emulators like Genesis Plus GX with better accuracy and close to 100% compatibility with all licensed and unlicensed games for quite a few years now.
A little more recently, we have Blastem then Ares emulators with devs more focused on improving accuracy for those interested in getting all test ROMs passing in their emus. Sure it isn't the NES emulator scene where you have have like hundreds of emulators to choose from but how many of them are accurate/compatible enough? Comparing to other systems from same time area (SNES, Neo Geo, PC Engine, etc), I would say Sega 8-bit and 16-bit fans have pretty much similar choices than others.
What is sure is that I don't know much system with cycle-accurate C and Verilog emulators based on chips die analysis. That alone shows how much Sega hardware has a dedicated base of talented people still reverse-engineering and documenting it after all these years, even when existing emulators are already good enough to play the majority of games without noticeable issues.
For most people, myself included, this doesn't matter at all.
For people looking for an extremely "pure" original experience, this is the closest you can get to original hardware - which is getting both more expensive and lower quality with time.
For the competitive speedrunning scene, incorrect emulation speed is a non-starter in some categories, and dropped inputs are a huge problem when they happen.
IIRC the cartridges were effectively just PROMs (I could be wrong and maybe they were fabbed / silicon and didn’t get programmed) which held the application code.
(The Genesis had a tiny ROM for the TMSS licensing check, but that was only 2KB, most of it image data -- and it was only used during system startup.)
On 8/16bit consoles everything was tied to the video chip. You essentially have to do your CPU work (including polling the controllers) during the vblank interval, a short time window that occurs 60 times per second on NTSC systems. This is essentially a zero-lag arrangement (max latency is 1/60th of a frame, average is 1/30th of a frame) but if you miss a controller input it's gone forever.
I'm not entirely sure how emulators handle this. They could deliver buffered controller inputs to the emulator on successive input polls for guaranteed delivery, but then the emulated software is going to see a lot of inputs with wacky timing that may or may not screw with game logic (think of a fighting game where you need to input specific things in sequence in specific time windows) so simply dropping inputs may be preferable to delivering a log jam of inputs.
As you are intuiting, this isn't generally an issue on modern hardware. Emulated games play fine. But, also... if you have a chance to sit down with real hardware connected to a CRT... it feels different. 1/30 frame of lag vs. multiple frames.
Emulators have tons of sync points, less than real hardware, but still plenty. The more sync points you add the slower emulation gets most of the time. Do we emulate transferring x length of bytes to a buffer in another part of hardware (video ram for example) one system bus wide word at a time or do we just cope it all at once and move on? etc.
Syncing aspects of the emulated hardware with each other is easy. You still have to count clock cycles somewhere. So you just execute the necessary number of CPU cycles while your DMA is running, then set the flag that it's done or whatever. And you have to do the same thing with hardware timers anyway — you trigger an interrupt after X clock cycles.
It's syncing the emulator itself to real time that's tricky.
It's also entirely possible to run an emulator at many times real-time and get the sound output correct, however you use it. You can use this to quickly get wav/mp3 copies of game music, for example.
https://junkerhq.net/MDFourier/
Genesis sound emulation is indeed tricky because there were multiple variants of the sound hardware in the Genesis over the years. Some emulators model multiple variants.
https://www.reddit.com/r/emulation/comments/104tgvs/sega_gen...
the genesis "specific" ym* cores look a lot more "authored"; commit history shows more activity around those files too
but thats just a guess... something that can generate verilog from chip images would be pretty cool...
Do we have tools for exposing specific layers instead of 2D images? It would, perhaps, be interesting to go with diagonal slices as we grind the chip and, aided by exaggerated vertical features, capture the full depth on a single pass.
- The X-Ray Tech That Reveals Chip Designs: https://spectrum.ieee.org/chip-x-ray
In this case, the project isn't very documented but it looks like fairly generic Verilog without a lot of vendor specific extensions. So, what you need is a Verilog toolchain which can synthesize the source code into a netlist, and then into a bitstream, and the right set of extra code to target an actual physical piece of hardware.
Right now, it looks like the only board support that's checked into the repository is for the Icarus Verilog simulation environment: https://github.com/nukeykt/Nuked-MD-FPGA/tree/main/icarus .
But, the overall setup looks pretty simple and generic, so it should (hopefully) be possible to synthesize to your board of choice by reimplementing run.v and memstubs.v towards an actual hardware configuration.
Basically what you'd want to do to start trying to run this on real hardware is to build a hosting environment which wired the inputs and outputs from `md_board.v` into the real hardware provided in your environment, possibly by integrating other soft-IP (ie - you could attach a cartridge emulator of some sort to the cartridge lines, your choice of video encoder to the video output, and so on).
A fully open-source FPGA/CPLD and toolchain would be very disruptive. How hard would it be?
It could be manufactured by any number of smaller foundries with older processes. No need for a 3nm node for this.
https://mister-devel.github.io/MkDocs_MiSTer/#what-is-mister...
The core of the MiSTer looks pretty beefy.
https://www.terasic.com.tw/cgi-bin/page/archive.pl?Language=...
Tho I’m glad this project exists that’s… a huge chunk of change for a 30 yr old console
but yes, it is fairly excessive if you just want to play games, emulation is absolutely "good enough" and even indistinguishable for most. We do it for the love of the hobby ;)
While other parts CAN fail it’s physical damage that’s much more likely a problem
Am I wrong there?
That tracks with what I thought. Great to know about the NeoGeo!
I don’t think the potential market for Amiga and ST keyboards for use with MiSTer justifies the investment, but I’d LOVE to see LK-411, Atari ST, Amiga, Sun, Symbolics, and other pre-PC-101 layouts as reasonably priced USB keyboards.
Someone elsewhere pointed out that PS1 disks (or any disk based system for that matter) suffers from disk rot, so likewise, what is now considered piracy should also be considered archival work since the original disks will stop working.
something something entropy, something something the inexorable passage of time.
Just… ouch on the cost of running it. Limits the effective impact somewhat.
I get why it’s expensive, but that doesn’t mean it’s not expensive.
https://ec.europa.eu/commission/presscorner/detail/en/IP_15_...
https://www.sec.gov/Archives/edgar/data/768251/0001193125153...
But I wouldn't place too much blame on the companies - COVID wrecked a lot of supply chains as well - as anyone who runs emulators on RPis will be able to confirm.
rpi shortage is a direct result of Broadcom (Avago) deciding to stop manufacturing chips that dont generate hundreds of millions in revenue a year. FPGAs were same deal, post merger Xilinx/Altera cut manufacturing.
Here is Nvidia not making more GPUs instead of lowering prices to something market would bear https://www.extremetech.com/gaming/report-nvidia-has-practic...
By contrast, this is the first effort (well second if you consider the nukeykt's initial C version) to try and recreate the entire system from analysis of silicon die photos. If you just want to enjoy some old games the difference is probably not particularly important, but Nuked-MD-FPGA is already passing some tests that the Mega SG does not. The screenshot in the lower right corner of the "Progress" section is a timing torture test ROM that the Mega SG fails at least 40 subtests for (I say at least because the results I've seen for Mega SG are from an earlier version of the ROM with fewer subtests).
Have you ever been in contact with them? I can imagine your and their skillsets would be very compatible with each other.
Thanks for explaining the screen grab from the torture test ROM; this is brilliant!
Just to be clear, Nuked-MD-FPGA is not my project. I'm the author of a traditional software emulator who happens to have been following development of this with keen interest. I do agree that it would be interesting to see the source of the Mega Sg though.
or included in that project(?) providing MiSTer for any FPGA?