Scott Hanselman

Emulating a PlayStation 1 (PSX) entirely with C# and .NET

September 13, 2019 Comment on this post [15] Posted in Gaming | Open Source
Sponsored By

I was reading an older post in an emulator forum where someone was asking for a Playstation 1 (PSX) emulator written in C#, and the replies went on and on about how C# and .NET are not suited for emulation, C# is far too slow, negativity, blah blah.

Of course, that's silly. Good C# can run at near-native speed given all the work happening in the runtime/JITter, etc.

I then stumbled on this very early version of a PSX Emulator in C#. Now, if you were to theoretically have a Playtation SCPH1001.BIN BIOS and then physically owned a Playstation (as I do) and then created a BIN file from your physical copy of Crash Bandicoot, you could happily run it as you can see in the screenshot below.

Crash Bandicoot on a C#-based PSX Emulator

This project is very early days, as the author points out, but I was able to Git Clone and directly open the code in Visual Studio 2019 Community (which is free) and run it immediately. Note that as of the time of this blog post, the BIOS location *and* BIN files are hardcoded in the CD.cs and BUS.cs files. I named the BIN file "somegame.bin."

PSX Emualtor in C# inside Visual Studio

A funny note, since the code is unbounded as it currently sits, while I get about 30fps in Debug mode, in Release mode the ProjectPSX Emulator runs at over 120fps on my system, emulating a PlayStation 1 at over 220% of the usual CPU speed!

Just to make sure there's no confusion, and to support the author I want to repeat this question and answer here:

Can i use this emulator to play?

"Yes you can, but you shouldn't. There are a lot of other more capable emulators out there. This is a work in progress personal project with the aim to learn about emulators and hardware implementation. It can and will break during emulation as there are a lot of unimplemented hardware features."

This is a great codebase to learn from and read - maybe even support with your own Issues and PRs if the author is willing, but as they point out, it's neither complete nor ready for consumption.

Again, from the author who has other interesting emulators you can read:

I started doing a Java Chip8 and a C# Intel 8080 CPU (used on the classic arcade Space Invaders). Some later i did Nintendo Gameboy. I wanted to keep forward to do some 3D so i ended with the PSX as it had a good library of games...

Very cool stuff! Reading emulator code is a great way to not only learn about a specific language but also to learn 'the full stack.' We often hear Full Stack in the context of a complete distributed web application, but for many the stack goes down to the metal. This emulator literally boots up from the real BIOS of a Playstation and emulates the MIPS R3000A, a BUS to connect components, the CPU, the CD-ROM, and display.

An emulator has to lie at every step so that when an instruction is reached it can make everyone involved truly believe they are really running on a Playstation. If it does its job, no one suspects! That's why it's so interesting.

You can also press TAB to see the VRAM visualized as well as textures and color lookup tables which is super interesting!

Visualizing VRAM

One day, some day, there will be no physical hardware in existence for some of these old/classic consoles. Even today, lots of people play games for NES and SNES on a Nintendo Switch and may never see or touch the original hardware. It's important to support emulation development and sites like with Donations to make sure that history is preserved!

NOTE: It's also worth pointing out that it took me about 15 minutes to port this from .NET Framework 4.7.2 to .NET Core 3.0. More on this, perhaps, in another post. I'll also do a benchmark and see if it's faster.

I encourage you to go give a Github Star to ProjectPSX and enjoy reading this interesting bit of code. You can also read about the PSX Hardware written by Martin Korth for a trove of knowledge.

Sponsor: Develop Xamarin applications without difficulty with the latest JetBrains Rider: Xcode integration, JetBrains Xamarin SDK, and manage the required SDKs for Android development, all right from the IDE. Get it today

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
September 16, 2019 5:29
Pretty neat, was not aware of this emulator. Reminds me of the C# Quake 3 "port" back in the .NET 1.1 days quelling the "C# isn't fast enough" qualms.

Definitely second the deep dive into reading emulator code to learn a ton in a short period of time.
September 16, 2019 7:27
Have you considered making a PR to contribute the .NET Core switch back to the main project? Would it be multiplatform at that point?
September 16, 2019 7:35
Did you send a diff, or create a public fork for your uplift to .Net Core 3? Also, does this work cross platform? Looks like winforms, and unsure of mono forms works, or could switch to eto forms as replacement options.
September 16, 2019 7:56
I was reading an older post in an emulator forum where someone was asking for a Playstation 1 (PSX) emulator written in C#
Why? This is the first time I hear that someone cares about the programming language of a piece of software.
September 16, 2019 8:07
Haven’t done a diff yet. Maybe when 3.0 is released.

No, it won’t make it cross platform, but it COULD if the winForms dependency is removed. Remember that Core 3.0 *can* call OS-specific APIs, and this is a Windows App, even though I moved it to Core 3.0.
September 16, 2019 14:13
This is very cool. In guess, in theory, the WinForms dependency could be swapped out for something like AvaloniaUI?
September 16, 2019 19:55
I find it so funny that people would say it’s not possible to emulate things with .NET. I’ve recently for fun written emulators for GameBoy and NES (not perfect, but very functional) in .NET Core 3 for fun. Also C64 emulator that does many things. I already wrote an iPaw 3630 emulator years ago that almost boots Linux on a serial terminal.

It’s fun and it’s nice with C#. But of course some things are a lot easier with lower level languages.
September 17, 2019 13:57
What a fantastic project
September 17, 2019 20:41
Hmm I wonder if we port the display code to use Xamarin Forms instead of winforms would that fix things (it’d be able to run on mobile, Linux, mac, and Windows)
September 18, 2019 13:21
Superb project. I was not aware of this. Gave a star on github.
September 18, 2019 17:57
Everyone who think that "C# is not fast enough" should read this
September 18, 2019 20:09
Still looking for a comprehensive list of .NET framework API calls missing, broken, no upgrade path in .NET core.

An upgrade path from .NET Framework to .NET core should exist without requiring a rewrite of code using primary .NET Framework APIs such as image handling, SMTP email server integration, HTTPContext, and using .NET core to build a WCF server.
September 19, 2019 17:45
There is a project on github which aims to do the same, but then for the PS2/PSP:
September 23, 2019 18:59
It seems to be the biggest project and it can't be easy to do it although C# is used in it. Read More
September 25, 2019 0:18
Very cool. I recently went out to Wikipedia to see what was happening in the world of gaming engines, specifically to see which languages were most widely adopted in the genera. C# is very common in game development, in particular this engine looks really interesting:

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.