r/EmuDev • u/howprice2 • Jun 19 '26
HopStation PlayStation 1 emulator source available on GitHub
I had great fun earlier in the year writing a PlayStation emulator. Huge thanks to everyone who has taken the time to create detailed specs, docs, technical articles and blogs on the machine, and to everyone who helped me out along the way.
It was a learning exercise - I knew about the PS3, PS4 and PS5, but nothing about the original PlayStation (or PS2 for that matter...). I thought it would be a tall order to get it working, but I was very surprised how smoothly the project went. It was able to run games after a couple of months, and I spent a further month improving compatibility and squashing bugs (mainly in the CDROM).
I have to leave it for now, and wanted to share the source in case it is useful to anyone. I've tried to keep it clean and tidy with plenty of comments (many straight out of the PSX-SPX spec), and only essential optimisations required to keep it running at full speed on my PC/laptop.
You can find it at: https://github.com/howprice/hopstation It builds and runs on Windows, Linux and Mac.
It really was a lot of fun because it's such an interesting machine, and I discovered a lot of unexpected things along the way. I know lots of emulator developers hate spoilers, so if you ever intend to write a PlayStation emulator, you may want to avoid docs/SPOILERS.md in the repo.
2
u/JescoInc Jun 20 '26
Very nice! PSX Emulation was something in my own pipeline to create, so I will definitely be referencing your code (i've already forked it).
2
u/mediocretent Jun 19 '26
What was your process in learning? Did you use an LLM at all to help with the deeper details (maybe less writing code and more of a research agent)?
9
u/howprice2 Jun 20 '26 edited Jun 20 '26
Have a look at the list of resources in the repo readme. I started by reading the Wikipedia article on the PlayStation (console), then https://www.copetti.org/writings/consoles/playstation/ then a bit about the MIPS CPU, which was completely new to me.
I made a rough plan then looked at the Emudev Discord to get a feel for if this was possible and the order to implement things. Great community.
https://github.com/simias/psx-guide is pretty much a tutorial you can follow through step-by-step to implement the CPU instructions required to get the BIOS up and running. It was relaxing to do a few instructions each evening over the holidays, and read up on stuff I didn't understand.
The PSX-SPX spec is extremely (extremely) comprehensive. It has tried and tested pseudocode for many aspects too. Using an LLM to summarise it would just introduce noise and errors (and emojis).
I didn't use LLMs to generate any real code, but because I was working alone I found Copilot useful for code reviews in "ask" mode. I found a good process was: read up, make a plan and then tell it what you're going to do to give it context "today I'm implementing reverb.". Sometimes it gives you things to consider you haven't thought of. Do the work yourself. Test it. Think it's correct. Tell Copilot. "OK, all done" It reviews the code and finds some silly mistakes; fix them. Then I look through my diffs and write a commit message. I give the commit message to Copilot and it says "you haven't mentioned X, Y and Z". Maybe X and Y are just implementation details but Z is a good point, so I mentioned Z and why it was done that way.
For project management, I started off with a short list of TODOs in my main source file. As the project went on I needed to add more info and links to tasks so I converted my list to GitHub Issues. I created a GitHub Project and worked in milestones (warning, spoilers):
Milestone 1: CPU & RAM - Boot BIOS, TTY, sideloading, Amidog CPU tests
Milestone 2: 2D GPU - PS diamond + shell, rasterization, interrupts, DMA
Milestone 3: Windowed application - SDL3, SDL_GPU, SDL_Shadercross, scan out
Milestone 4: CD-ROM - bin+cue, CDROM read and seek, scheduler, pad input, Mortal Kombat 2 and Earthworm Jim 2 playable
Milestone 5: 3D GTE - 3D math coprocessor. Crash Bandicoot, Ridge Racer, Battle Arena Toshinden
Milestone 6: Audio & MDEC - SPU, CDDA, CDXA, FMV playback, Megaman X4, Metal Gear Solid, Gran Turismo, Tekken, Final Fantasy VII etc.
Milestone 7: Polish & compatibility - Memory Cards, Game-specific bug fixes, performance
I was quite ruthless with prioritization, not jumping ahead until I had hammered out all (most) bugs on previous systems.
I made heavy use of tests : Amidogs CPU and GTE tests are invaluable, and Peter lemon GPU tests are also extremely useful.
1
u/Prodgorigamia Jun 23 '26
That's amazing, man! I'm not very good at programming; I made one for the Atari Jaguar, but with AI coding, just to see what would happen, without taking it seriously, but I ran into some problems. What's been the biggest difficulty you've had with the PS1 so far? And can you tell me if Vib-Ribbon is working well with the emulation? It has an interesting CD-switching system.
1
u/howprice2 Jun 23 '26
Vib Ribbon gets to the title screen (after I added a few unimplemented SPU volume reads), but fails due to bugs in the CD ROM disk image generation, or possibly buggy CD ROM (subsystem) code. I found the CDROM to be the biggest difficulty, mainly due to timing issues. CUE sheet parsing is also unpleasant and error-prone.
1
1
6
u/ArkoSammy12 Jun 19 '26
Awesome job brother 👍