Git Product home page Git Product logo

nesemu's Introduction

NESEMU: emulates the NES game console on an ESP32 with a 320x240 ILI9341 TFT screen, audio output, various controller inputs and SD card

Supports classic NES/SNES/PSX controllers or raw GPIO buttons.

NESEMU

NESEMU uses the Arduino IDE framework to compile and flash/upload the binary to an ESP32 module (wemosmini).

     ---------
    |      25 |--------> audio out
    |         |  gnd <-> gnd
    |         |
    |      5  |--------> LCD ILI9341 CS
    |      0  |--------> LCD ILI9341 RESET
    |      2  |--------> LCD ILI9341 DC
    |      23 |--------> LCD ILI9341 MOSI
    |      18 |--------> LCD ILI9341 SCLK
    |      19 |--------> LCD ILI9341 MISO
    |         |  3v3 <-> LCD ILI9341 LED
    |  ESP32  |  3v3 <-> LCD ILI9341 VCC
    |         |  gnd <-> LCD ILI9341 GND
    |         |
    |      15 |--------> SD card CS
    |      13 |--------> SD card MOSI
    |      14 |--------> SD card SCLK
    |      12 |--------> SD card MISO
    |         |  3v3 <-> SD card VCC
    |         |  gnd <-> SD card GND
    |         |
    |      4  |--------> PSX controller CMD
    |      21 |--------> NES/SNES/PSX controller DATA/DAT
    |      22 |--------> NES/SNES/PSX controller CLOCK
    |      27 |--------> NES/SNES/PSX controller LATCH/ATT
    |         |  3v3 <-> NES/SNES/PSX controller VCC/3V3
    |         |  gnd <-> NES/SNES/PSX controller GND
     ---------

NES        ___
    DATA  |o o| NC
    LATCH |o o| NC
    CLOCK |o o/ 3V3
    GND   |o_/

SNES       _
    3V3   |o|
    CLOCK |o|
    LATCH |o|
    DATA  |o|
          |-|
    NC    |o|
    NC    |o|
    GND   |o|
           -  	
PSX ___________________
    \o o o|o o o|o o o/
     -----------------
     1 2 3 4 5 6 7 8 9
		 
    1->DATA, 2->CMD, 4->GND, 5->3V3, 6->ATT, 7->CLOCK, 9->ACK

Build

The emulator is based on the nofrendo emulator (by Matthew Conte) which was ported to the ESP32 esp-idf framework by SpriteTM. Later versions from different people added various extras to the build. This version uses the code from various sources originating amoung others from "MittisBootloop" version and the build was then transfered to the Arduino IDE framework as a friendlier development platform. Note that this is still work in progress and not all features has been fully tested. Lot of effort went into getting the emulator to shift data fast enought through the SPI interface to the LCD to make it run as fast as possible. Currently the CPU (in a separate task) is just as fast as transfering data with DMA. There is options to stretch the screen along the X-axis but it has two drawbacks, if the game is of scrolling type then the crude upsampling (only CPU mode with interlace supports bilinear upscaling) will make some pixel flickering. Due to the larger amount of data it will take longer to transfer to the LCD but for interlaced mode and SPI running at 80MHz it is still a viable option. Pressing select and left simultaneously will bring up the in game menu while pressing select and start will do a reset. To get back to the ROM menu you'll need hit the reset button on your ESP32 module or power cycle the ESP32.

Options

The file config.h in the top directory contains a few options and settings as well as the ESP32 pin mapping. Note that the LCD needs to use the VSPI interface to work fast/properly, additionally there is an option to rotate the screen 180 deg. The screen is up scaled (256->320 pixels) with either crude nearest sample or bilinear (the x axis up scaling can be turned on and off in the in game menu select + left). Due to some coding tricks bilinaer is just as fast as the more crude nearest sample but bilinear looks much better. Y axis is not scale at all. The default way to update the screen is in interlaced mode (odd/even lines as opposed to progressive, full screen update) using the CPU/SPI buffer. This will allow the refreshrate to hit 60FPS even with the screen stretched along the x-axis. There are options to use DMA but in its current form there is no speed benefit over the CPU. ROMs can be put on the SD card (formatted as FAT) with 8.3 file names and then mapped to the file menu with the "roms.txt" file that also needs to be in the root dir of the SD card. Note that the selected ROM gets memory mapped in the internal EEPROM of the ESP32 which means some wearing on its finite amount of write cycles (100k writes?). If the same ROM is selected after reset or power on then only a verify (no write) will take place to make sure the data is intact. This will then avoid a rewrite of the ROM image to the EEPROM.

Controllers

The code base supports different types of controllers but only one at the time. Supported ones are NES, SNES, PSX or raw GPIO buttons (last two are not tested by me). Select the one you want in the config.h file

Compiling

Use the Arduino IDE framework to compile and upload to the ESP32 (tested with V1.8.13 with ESP lib V1.04)

Copyright

Bit of a mixed bag here... Code in this repository is Copyright (C) 2016 Espressif Systems, licensed under the Apache License 2.0 as described in the file LICENSE and components of nofrendo is Copyright (c) 1998-2000 Matthew Conte ([email protected]) and licensed under the GPLv2. Any changes in this repository are otherwise presented to you copyright myself and lisensed under the same Apache 2.0 license as the Espressif Systems repository.

Enjoy, Corn

nesemu's People

Contributors

cornn64 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

dushino dionesde

nesemu's Issues

frequency

Hello
Why(NES Games) it works in low frequency on the main console 6502 on 3 MHz
But Why should the frequency be high for the simulator? by Atmega and ESP32 ?
thanks

Crash after I2S fix

I am trying to get this project working on a LOLIN D32 with an ILI9341 display and a MAX98357A I2S DAC.

I had it working without sound for some time but since I changed the settings from direct DAC to I2S it stops working whenever I start a ROM.

in video_audio.c I disabled the build in DAC

		.mode = I2S_MODE_MASTER | I2S_MODE_TX,
//		.mode = I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN,

an I added the pin configuration to what I am using in my other projects:

static const i2s_pin_config_t pin_config = {
	.bck_io_num = 27,
	.ws_io_num = 26,
	.data_out_num = 25,
	.data_in_num = 0 // I2S_PIN_NO_CHANGE
};	
i2s_set_pin(I2S_DEVICE_ID, &pin_config);

I don't hear any sound in the menu (don't know if this is normal) but when I start some ROM it get this messages and the system freezes (no display updates, menu button not working, ...):

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1184
load:0x40078000,len:13260
load:0x40080400,len:3028
entry 0x400805e4
Game controller initalizing
GPIO Control initated
Init SPI bus
Init SPI bus completed
Adding screen device
Adding screen completed
LCD ILI9341 initialization.
LCD initialization complete.
Start boot menu init
Reading rom list
ROM[1] icon[$] name[Super Mario Bros] file[smb.nes]
ROM[2] icon[;] name[Tetris] file[tetris.nes]
ROM[3] icon[+] name[Duck Tales] file[dtales.nes]
Found 3 ROMs
Finished boot menu init
No errors, carry on
Showing boot menu
Menu selection is /spiffs/smb.nes
NoFrendo start!
Starting main loop with file: /spiffs/smb.nes
Finished initializing sound
free heap after sound init: 234896
Game controller initalizing
GPIO Control initated
free heap after input init: 232472
video driver: Simple DirectMedia Layer at 486555958x240
vid_init done
vid_init done
PPU memory allocated and cleared
partition type = 0.
partition subtype = 17.
partition starting address = 150000.
partition size = 140000.
partition label = app1.
partition encrypted = 0.
Reading rom from /spiffs/smb.nes
Loaded/Verified 40976 ROM bytes mapped on EEPROM area
Initialized. ROM @ 0x3f410000
Head: 0x3f410000 (4e 45 53 1a)
SRAM Present
created memory mapper: None
setting up mapper 0
reset memory mapper
Timer install 60Hz
Game controller initalizing
GPIO Control initated
Init SPI bus
Init SPI bus completed
Adding screen device
Adding screen completed
LCD ILI9341 initialization.
LCD initialization complete.
Start boot menu init
Reading rom list
ROM[1] icon[$] name[Super Mario Bros] file[smb.nes]
ROM[2] icon[;] name[Tetris] file[tetris.nes]
ROM[3] icon[+] name[Duck Tales] file[dtales.nes]
Found 3 ROMs
Finished boot menu init
No errors, carry on
Showing boot menu
Menu selection is /spiffs/smb.nes
NoFrendo start!
Starting main loop with file: /spiffs/smb.nes
Finished initializing sound
free heap after sound init: 234896
Game controller initalizing
GPIO Control initated
free heap after input init: 232472
video driver: Simple DirectMedia Layer at 486555958x240
vid_init done
vid_init done
PPU memory allocated and cleared
partition type = 0.
partition subtype = 17.
partition starting address = 150000.
partition size = 140000.
partition label = app1.
partition encrypted = 0.
Reading rom from /spiffs/smb.nes
Loaded/Verified 40976 ROM bytes mapped on EEPROM area
Initialized. ROM @ 0x3f410000
Head: 0x3f410000 (4e 45 53 1a)
SRAM Present
created memory mapper: None
setting up mapper 0
reset memory mapper
Timer install 60Hz

Also I can't get the micro sd card reader to work with this project. It works in a stand alone project without changing the connections, but with nesemu it does not. But as long as I can use the SPIFFS this is no big deal for me.

Any ideas what I did wrong with the I2S configuration ?

UPDATE: I thought it's just a brownout because of the MAX98357 consuming too much power from the LOLIN D32 but even with the I2S DAC removed it hangs after "Timer install 60 Hz". But if I change i2s_set_pin(I2S_DEVICE_ID, &pin_config); back to i2s_set_pin(I2S_DEVICE_ID, NULL); it works without sound (but I can play Super Mario)

Couldn't find rom partition!

Please help how to solve this issue. Thanks!

01:36:03.587 -> Showing boot menu
01:36:03.775 -> Menu selection is /spiffs/tetris.nes
01:36:03.775 -> NoFrendo start!
01:36:03.775 -> Starting main loop with file: /spiffs/tetris.nes
01:36:03.775 -> free heap after sound init: 4444584
01:36:03.822 -> Game controller initalizing
01:36:03.822 -> NES Control initated
01:36:03.822 -> free heap after input init: 4442148
01:36:03.822 -> video driver: Simple DirectMedia Layer at 486555958x240
01:36:03.822 -> vid_init done
01:36:03.822 -> vid_init done
01:36:03.916 -> PPU memory allocated and cleared
01:36:03.916 -> Couldn't find rom partition!
01:36:03.916 -> abort() was called at PC 0x401054f2 on core 1
01:36:03.916 ->
01:36:03.916 -> ELF file SHA256: 0000000000000000
01:36:03.916 ->
01:36:03.916 -> Backtrace: 0x4008e000:0x3ffb1de0 0x4008e279:0x3ffb1e00 0x401054f2:0x3ffb1e20 0x400e57cf:0x3ffb1e40 0x400e1686:0x3ffb1e60 0x400e1a5f:0x3ffb1e90 0x400d76ba:0x3ffb1ee0 0x400e296b:0x3ffb1f10 0x400e29e3:0x3ffb1f50 0x400e28b9:0x3ffb1f70 0x400d1d77:0x3ffb1f90 0x400e3ea1:0x3ffb1fb0 0x4008f24e:0x3ffb1fd0
01:36:03.916 ->
01:36:03.916 -> Rebooting...

Having issues compiling

I have been having issue after issue getting your NES emulator to compile.

I'm using an ESP32-S3 and compiling with the Arduino IDE. It has dozens of errors ranging from missing libraries to the use of the RTC to set the speed of the CPU. I'm wondering how you got it to compile and upload.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.