Emulating NES CPU and PPU on PIC32, too slow?
Posted: Wed Dec 04, 2024 3:01 am
Hey everyone, long time!
I've been off programming in PIC32-land for a while now. Very much enjoying it! Here's my GitHub page if you are interested: https://github.com/stevenchadburrow/AcolyteHandPICd32
Anyways, I recently had a crazy idea to run a C-based NES emulator on this PIC32. Why use FPGA's when you got something so much cooler, right?
Wrong. I did manage to actually get it 'running' (I copied code from https://github.com/franzflasch/nes_emu and made necessarily modifications). But its *magnitudes* slower than what I need. I did some cycle counts and its literally hundreds if not thousands of cycles per single CPU and PPUx3 cycles. So the NES runs at 1.79 MHz, the PPU runs 3 times faster, that's just roughly 4 * 1.79 MHz = 7.16 MHz equivalent. My PIC32 is running a nominal 100 MHz lets say, thus 100 / 7.16 = 13.966 = 14x PIC32 cycles per 1x NES emulated cycles. [ This is all very rough math. ]
Thus to keep up the hardware emulation, my PIC32 would have to be doing all the work of the CPU and PPU in about 14 clock cycles. That's literally impossible.
My question to you guys: Am I thinking about all of this correctly?
When I first saw it working at all, that was neat. But then it was SO SLOW, barely crawling. This morning I optimized some code and got it twice as fast as previously, but I think I need like 30+ times the speed to make it run smoothly. Thus *magnitudes*. Simple code optimization won't cut it. Yes?
Thanks for any insight.
Chad
I've been off programming in PIC32-land for a while now. Very much enjoying it! Here's my GitHub page if you are interested: https://github.com/stevenchadburrow/AcolyteHandPICd32
Anyways, I recently had a crazy idea to run a C-based NES emulator on this PIC32. Why use FPGA's when you got something so much cooler, right?
Wrong. I did manage to actually get it 'running' (I copied code from https://github.com/franzflasch/nes_emu and made necessarily modifications). But its *magnitudes* slower than what I need. I did some cycle counts and its literally hundreds if not thousands of cycles per single CPU and PPUx3 cycles. So the NES runs at 1.79 MHz, the PPU runs 3 times faster, that's just roughly 4 * 1.79 MHz = 7.16 MHz equivalent. My PIC32 is running a nominal 100 MHz lets say, thus 100 / 7.16 = 13.966 = 14x PIC32 cycles per 1x NES emulated cycles. [ This is all very rough math. ]
Thus to keep up the hardware emulation, my PIC32 would have to be doing all the work of the CPU and PPU in about 14 clock cycles. That's literally impossible.
My question to you guys: Am I thinking about all of this correctly?
When I first saw it working at all, that was neat. But then it was SO SLOW, barely crawling. This morning I optimized some code and got it twice as fast as previously, but I think I need like 30+ times the speed to make it run smoothly. Thus *magnitudes*. Simple code optimization won't cut it. Yes?
Thanks for any insight.
Chad