Close

Introduction and some porting instructions!

A project log for NES Emulator (2) for the PIC32MZ-EF

A simple NES emulator for the PIC32MZ-EF microcontroller, complete with sound and controls.

nyh-workshopNYH-workshop 06/03/2018 at 06:210 Comments

As being said in the log title. I had been doing this in an on-and-off manner since 2015 - I started this out using a STM32F4 discovery board with some screen on it and 8MB SDRAM. The code was obtained from the OpenEDV forums - with my limited Mandarin, I had to constantly use the Google translate so I won't get lost in that ocean!  It worked... but there's no sound, and with all kinds of troubles I went through in life, I shelved that for like two years without working on this one.

It may seem as a lame excuse, and I admit - NES emulation is not something I can learn in a mere few weeks . Despite being such an old (and mostly being copied by Chinese factories for cheap knockoffs) architecture, it is still being a very popular console for everyone. I used to have a "Micro Genius" when I was a kid and spent some weekends playing those games.

Back to the main story - I have taken that code again and try to see if any of the PIC32MZs could fit on it. It did - and I have used the beaglescout007's emulator code to start with. It worked - but some games were not emulated properly. I will have to put this first try on the Github someday!

Then, curiously, I found that same emulator I took in 2015 and see if it also fit into that microcontroller. There are some major challenges there - especially the serial TFT and the sound generation mechanism.

Let me point out some important matters regarding to the porting:

1.) nes_main.cpp

2.) APU.cpp 

 nes_main.cpp, NesFrameCycle():

       //Added APU routines:
       switch (PPU_scanline) {
        
        case SCAN_APU_CLK1: // 240Hz
        case SCAN_APU_CLK3: // 240Hz
          pNesX_ApuClk_240Hz();
          break;

        case SCAN_APU_CLK2: // 240Hz 120Hz
          pNesX_ApuClk_240Hz();
          pNesX_ApuClk_120Hz();
          break;

        case SCAN_APU_CLK4: // 240Hz 120Hz 60Hz
          pNesX_ApuClk_240Hz();
          pNesX_ApuClk_120Hz();
          pNesX_ApuClk_60Hz();
          break;

       default: break;           
     }

      I believe that I could put the same code into other emulators - and this is the first one I have tried so          far.

3.) Joypad.cpp:

So that concludes the log for today. There are some other issues like the sounds still being nasty and the emulator doesn't work as it should for some games, and hopefully some NES experts can share us some cool ideas here!

Discussions