Cycle-Accurate Nintendo 64 Emulator
Go to file
Giovanni Bajo 87ebca00b5 Fix a few pipelining bugs with RSP
1) Setting SP_PC was not resetting the pipeline. This caused that
changing the PC within a HALT/UNHALT sequence was still causing
previous instructions in the pipeline (at the old address) to be
executed. This is not how the hardware works: SP_PC is immediate and
discards the whole pipeline.

2) BREAK did not correctly halt the processor at the right instruction,
which in turn caused resumption after HALT to execute the wrong
set of instructions. This was caused by the fact that the SP_STATUS
change was written into the EXDF latch, which in turn takes 3 cycles
to reach completion. Instead, we now use the DFWB latch, and we cause
it to abort the RSP cycle if the processor is halted. This happens
at the beginning of next cycle, which is the correct moment.

2bis) Since we are at it, use rsp_status_write to modify the RSP in
this case, rather than a direct write to the register. This change
fixes a race condition: SP_STATUS must be accessed atomically when
cen64 runs in multithreaded mode. To use rsp_status_write, we need
to introduce a nonexisting SP_SET_BROKE bit: we use the MSB, but then
mask it out in MTC0 to avoid some code to inadvertently have that bit
set.

3) When unhalting after BREAK, it's important to keep the correct
PC which comes from the EX stage (the one that was going to be
executed if BREAK didn't occur). Before, it was using the IF PC (fetch)
which is farther in the future.

Fixes #155
2021-12-17 00:23:47 +01:00
.github/workflows Check linux workflow builds. 2021-01-22 14:06:52 +00:00
ai Remove unused global bus pointer variables 2020-05-15 21:28:24 +02:00
arch Fix arch/x86_64/rsp warnings 2021-09-07 23:11:00 +02:00
assets Initial commit. 2014-03-08 11:12:15 -05:00
bus Implement debugging hooks into vr4300 2021-01-10 17:07:21 -07:00
cmake Cleanup toolchain file. 2021-01-22 13:36:16 +00:00
common Implement hash table 2021-01-10 17:05:35 -07:00
dd Implement RTC write support 2021-09-04 22:02:29 +02:00
debugger See long description 2015-07-01 18:44:21 -05:00
device Add Dinosaur Planet to cart DB 2021-02-20 18:39:05 +01:00
gdb Report full pc instead of truncated address 2021-03-12 18:20:02 +01:00
os Show Windows console when isviewer is present. 2021-09-06 23:35:40 +02:00
pi Improve PI DMA implementation. 2021-06-23 20:11:44 +02:00
rdp RDP Use OR to Set STATUS Command Buffer Ready Bit 7 & Definition 2019-05-02 19:07:04 +01:00
ri Remove unused global bus pointer variables 2020-05-15 21:28:24 +02:00
rsp Fix a few pipelining bugs with RSP 2021-12-17 00:23:47 +01:00
si Implement RTC write support 2021-09-04 22:02:29 +02:00
util Teach the profiler about L1D misses 2020-12-21 19:05:07 +02:00
vi Remove unused global bus pointer variables 2020-05-15 21:28:24 +02:00
vr4300 Fix two bugs in COP0 count 2021-06-13 23:19:07 +02:00
.appveyor.yml Add CI configuration files 2018-09-16 16:38:17 +03:00
.gitattributes See long description 2015-07-01 18:44:21 -05:00
.gitignore See long description 2015-07-01 18:44:21 -05:00
.travis.yml Update Travis images 2020-03-27 00:19:16 +03:00
cen64.c Show Windows console when isviewer is present. 2021-09-06 23:35:40 +02:00
cen64.h See long description 2015-07-01 18:44:21 -05:00
CMakeLists.txt Show Windows console when isviewer is present. 2021-09-06 23:35:40 +02:00
common.h.in Basic RSP LTV/STV support 2020-04-15 07:38:09 +02:00
CONTRIBUTORS Update contributors and README.md. 2016-02-27 16:04:24 -05:00
LICENSE See long description 2015-07-01 18:44:21 -05:00
README.md Update iconv and openal links in readme. 2021-01-22 13:57:20 +00:00
VERSION Initial commit. 2014-03-08 11:12:15 -05:00

Just give me a copy!

Buildbot: https://github-buildbot.cen64.com/builders

About

Yes, another Nintendo 64 emulator. This one, however, aims for perfect emulation by emulating the hardware inside of the Nintendo 64 itself, down to the register-transfer level (RTL). At the same time, I've tried to keep things as optimized as possible in hopes that CEN64 will someday run ROMs at full speed, even on modest systems.

Why?

CEN64 is my pet project. It's something I pick up whenever I get bored. To me, what Nintendo and SGI did with this console is nothing short of amazing. The ingenuity and design of the hardware was well-ahead of it's time, and it is an absolute blast to reverse-engineer and study. I started this project in order to learn more about what really went on at the hardware level back in the (good old) days.

Thank you to every single one of you developers for filling my childhood with excellent memories. I'd also like to thank the community on all their hard work and effort spent reverse-engineering this little gem. Without further ado... "Get N or get out"!

Development

If you want to contribute, please do! Pull requests are most certainly welcome. Feel free to add yourself to the CONTRIBUTORS file as well.

Keyboard controls

  • 3D stick: arrow keys (hold shift to "walk")
  • A button: X
  • B button: C
  • Z button: Z
  • Start button: enter
  • L/R buttons: A/S
  • C-pad: TFGH
  • D-pad: IJKL

Build requirements

  • CMake
  • iconv
  • OpenAL
  • OpenGL

To build on Fedora 29, do: sudo dnf install cmake make mesa-libGL-devel openal-soft-devel

To build for Windows on Fedora 29, do: sudo dnf install cmake make mingw64-{gcc,iconv,openal}

To build for Windows on Windows XP..10, do:

  1. Install MSYS 1.0.11: https://sourceforge.net/projects/mingw/files/MSYS/Base/msys-core/msys-1.0.11/MSYS-1.0.11.exe/download
  • Say yes to post install
  • Say no to mingw is installed
  • Press enter a few times to finish the install
  1. Extract contents of "mingw64" directory to "MSYS\mingw" directory: https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-posix/seh/x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z
  2. Copy "MSYS\mingw\bin\mingw32-make.exe" to "MSYS\mingw\bin\make.exe"
  3. Extract OpenAL "bin, libs, include" directories to "MSYS\mingw\x86_64-w64-mingw32" directory: https://openal-soft.org/openal-binaries/openal-soft-1.21.0-bin.zip
  4. Extract iconv to "MSYS\home\yourname\libiconv" directory: https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz
  5. Run MSYS & type "cd libiconv" Enter, followed by "./configure --disable-shared" Enter, followed by "make install" Enter
  6. Extract CMake "bin, doc, man, share" directories to "MSYS" directory: https://github.com/Kitware/CMake/releases/download/v3.13.4/cmake-3.13.4-win64-x64.zip
  7. Extract CEN64 source to "MSYS\home\yourname\cen64" directory: https://github.com/n64dev/cen64
  8. Run MSYS & type "cd cen64" Enter, followed by "cmake-gui" Enter
  9. Add the "MSYS/home/yourname/cen64" directory to "Browse Source..." & "Browse Build...", then Generate MSYS compatible files:
  • Add OpenAL "MSYS/mingw/x86_64-w64-mingw32/include/AL" as "OPENAL/OPENAL_INCLUDE_DIR" & "MSYS/mingw/x86_64-w64-mingw32/lib/libOpenAL32.dll.a" as "OPENAL/OPENAL_LIBRARY" (if they are not found)
  • Make sure to use libiconv static lib (Not DLL) "MSYS/local/lib/libiconv.a" as "ICONV/ICONV_LIBRARIES"
  • Select "SSE4.1" or "AVX" as "Ungrouped Entries/CEN64_ARCH_SUPPORT" & make sure VR4300_BUSY_WAIT_DETECTION is ticked
  1. Click "Configure" then click "Generate" to get the makefiles, then quit cmake-gui, & type "make" Enter

Usage

  • How do I run cen64?
    You will need a valid pifdata.bin file (NTSC or PAL), & a ROM in .z64 format (in big-endian format).

To run cen64 without multithreading (slower):
cen64 pifdata.bin ROM.z64

To run cen64 with multithreading (faster):
cen64 -multithread pifdata.bin ROM.z64

  • How do I run 64DD games?
    You will need a valid 64ddipl.bin file (NTSC JPN or USA), & a 64DD disk image file in .ndd format.

cen64 -ddipl 64ddipl.bin -ddrom DISK.ndd pifdata.bin

  • How do I setup save files for games?
    N64 has various types of save formats used in games...
    You will need to specify the save type yourself, cen64 will create the file if it does not exist.

EEP4K:
cen64 -eep4k eep4k.bin pifdata.bin ROM.z64

EEP16K:
cen64 -eep16k eep16k.bin pifdata.bin ROM.z64

FLASH:
cen64 -flash flash.bin pifdata.bin ROM.z64

SRAM:
cen64 -sram sram.bin pifdata.bin ROM.z64

  • The game runs, but I get strange errors, like multiple ocarinas in Majora's Mask.

You can fix the issue by using the -flash option on the command line:
cen64 -flash flash.bin pifdata.bin majora.z64