Please sign in to access this page

Stats

1
Projects
14
Devlogs
54
Votes
1
Ships

Coding Time

All Time: 195h 5m
Today: 0h 0m

Member Since

June 22, 2025

Badges

1
🚢
Maiden Voyage
you shipped your first project! the journey begins...

Projects

1
psx-emu (PS1 Emulator)
14 devlogs • over 1 year ago

Activity

Final devlog before shipping!
<br/>
- I spent most of this devlog's time trying to get CDDA audio to work. CDDA audio is raw CD audio that is streamed from the CDROM controller to the SPU, and is used by some games to play music. In theory, CDDA should be pretty simple to get working, but in practice it took me way too long because for some reason games were playing static (garbage audio data) instead of music. This turned out to be caused by a bug in how i calculated the start and end of a track. After fixing that, CDDA audio was STILL broken - games were seeking to the wrong part of the disc to play music. What i didn't realise was that CD addresses (in minute:second:sector format) used BCD (binary coded decimal) for some reason instead of regular numbers. After properly decoding the BCD numbers CDDA was finally working (although it still doesn't sound fully correct - could be a clamping issue?). This basically means my emulator is a CD player now lol.
<br/>
After finishing CDDA audio, i wanted fix a few minor bugs to get the emulator ready for shipping:
<br/>
- I mostly fixed audio stutters by making the sample buffer larger
- I fixed a bug in my mask bit logic (a pixel with the mask bit set is write-protected) which was causing white rectangles to be drawn over everything in silent hill.
<br/>
And thats it! Since the start of SoM, i've gone from not being able to even boot any games to being able to play a sizable portion of the PS1 catalogue! With sound emulation now mostly finished, the emulator is actually nearly done (I just need to implement the video decoder (MDEC), dualshock controllers, memory cards, and improve the CDROM emulation).
<br/>
- If you are interested in learning more about the PlayStation 1 hardware, check out psx-spx: https://psx-spx.consoledev.net/
- If you want to learn more about emulation (or write your own emulator), go to: https://emudev.org/ (and make sure to join the discord, the people there are super helpful)
<br/>
Image: Silent Hill with correct graphics

Update attachment

Implementing the last few features of the SPU turned out to be surprisingly easy, especially after doing reverb. The noise generator was around 50 lines of code (it's basically just a linear feedback shift register, or LFSR, which is then interpreted as a 16 bit PCM sample), and the pitch modulation was probably less than that. I tested these features using Final Fantasy VII, which uses both at the same time for a sword swing sound effect.
<br/>
Capture buffers and SPU IRQs (Interrupt Request is generated when a specified address is read/written to in sound RAM) were similarly simple, and the game best known for using these features is Metal Gear Solid 1 (MGS1) (which i said in the last devlog should boot with now SPU IRQs implemented). The reason this devlog is 8 hours long is because it turns out implementing SPU IRQs did NOT make MGS1 boot - instead it just freezes in a loop with a black screen. I had no idea what was making it freeze, so i spent an entire day troubleshooting my emulator and reverse-engineering the game to try and figure out why it was freezing. Eventually I figured out from cross-referencing MGS1's ghidra output with the fan decompilation of MGS1, I found that it was waiting for a DMA IRQ to be fired, and my DMA IRQs (which i had never bothered to test) weren't being fired.
<br/>
After fixing that bug, MGS1 boots! However it didn't get very far because my SPU IRQs were broken (which is why i wanted to get MGS1 working: to test my SPU IRQs). The next day (since by this point it was 1am lol) I fixed all the bugs in my SPU IRQ implementation (and some other SPU bugs which were preventing IRQs from firing), and now MGS1 actually works!! (there are still graphical issues though, which isn't surprising since metal gear solid 1 is infamous for pushing the PS1's GPU to its limits).
<br/>
Thanks to these fixes the following games are playable:
- Tony Hawk's Pro Skater 3
- Medal of Honor
- Chrono Trigger
- CTR - Crash Team Racing (graphics are super messed up bc of a CDROM issue)
<br/>
Next i'm gonna work on CD audio (streaming audio from the CDROM drive to the SPU), fix some graphical bugs in MGS1, and fix the audio stutter that happens sometimes (i think its a problem with the audio backend).
<br/>
You can see the commits for this devlog here: https://github.com/Iamhere345/psx-emu/commits/main/?since=2025-09-26&until=2025-09-28
<br/>
Image: Metal Gear Solid is now playable

Update attachment
Earned sticker

So implementing reverb turned out be extremely painful, not because there was anything difficult about it (its basically just copying the formulas from the documentation), but because of this frustrating bug in my code which took me most of yesterday and all of today to find.
<br/>
For some reason the reverb was outputting very loud background noise instead of reverberations (I cant really explain it but it sounded BAD), and i thought that something was wrong with the reverb code itself, so i rewrote it 3 times, but NOPE - i wasn't sign-extending the volume registers properly. That took me (probably more than) SEVEN HOURS to figure out.
<br/>
Anyway, thats the hardest part of the SPU done, so now i can move on to IRQs, noise channels and capture buffers, and then the SPU is 100% complete (and hopefully metal gear solid should boot since it needs SPU IRQs). P.S silent hill gets ingame now because most of the SPU is working, so thats cool.
<br/>
Video: (VOLUME WARNING) you can hear the reverb effect when you go through the tunnel in ridge racer, but for some reason the recording has some audio artifacts (these only show up in the recording, it sounds fine when im playing it).

Earned sticker

I fixed the audio quality and got sound effects playing in crash bandicoot!
<br/>
- It turns out the reason why the audio quality was so bad (see last post's video) was because I missed a pair of parenthesis (again) when decoding the ADPCM sample :(
- The reason crash's sound effects weren't playing was because of an off-by-one error in the ADSR phase transition logic.
- In the process of finding and fixing these bugs I also just generally cleaned up the SPU code a bit and improved accuracy in some places.
<br/>

Next i'm gonna implement sweep envelopes (which is just a simpler version of the ADSR envelope so it shouldn't take long), and then get started on reverb, which should make the BIOS sound really nice.
<br/>

Video: Crash Bandicoot with fully correct audio (last crash bandicoot video i promise)

Earned sticker

Did some more work on the SPU and now everything sounds a lot better! (the bios still sounds like its underwater tho lol)
<br/>
Changes made:
<br/>
- Implemented proper volume, which didn't take very long (all it is is just multiplying the voice sample / mixed sample by the volume). Doing this also meant I needed to implement stereo sound, which was also pretty simple.
<br/>
- Implemented ADSR (attack, decay, sustain, release) envelopes, which alter the volume over time in a way that mimics pressing a piano key. There aren't really any tests for this but from what i can tell it's working correctly and the bios sounds a lot better with ADSR enabled.
<br\>
- mostly fixed the audio in crash bandicoot: the reason it sounded so messed up was because i wasn't handling writes to sound ram correctly, so it was just playing garbage basically. As soon as I fixed that the theme song sounded perfect, but sound effects still aren't playing for some reason.
<br/>
- Added interpolation to the audio samples to make them sound less crispy.
<br/>

Up next: figure out whats stopping crash's sound effects from playing, volume envelopes, noise generation, SPU IRQs, reverb (maybe). After all thats finished the SPU is basically done and i can move on to either the MDEC (hardware FMV decoder) or keep improving my CDROM code.
<br/>

Video: crash bandicoot with the theme song playing.

Earned sticker

Now that the GTE is finally done, i've started working on the SPU (sound processing unit)! At the moment I only have very simple ADPCM (compressed PCM audio sample) decoding and playback working (and i think there might be a bug in there somewhere but its hard to tell since its just audio).

Even without ADSR or CD audio (CDDA/XA-ADPCM), im getting some (very messed up) signs of life from the bios, and even parts of the crash bandicoot theme song are recognisable.

Getting the actual audio interface set up was a bit painful since I after a set it up the emulator just crashed due to a stack overflow (with no info on what was causing it), but this turned out to be because i was allocating 512k of sound ram onto the stack lol.

Right now im trying to figure out why the audio starts lagging behind the rest of the emulator (at some points its 5+ seconds behind), but i think im gonna look into that more once i get things sounding better.

Next im gonna start working on the volume / ADSR.

Video: audio output from the bios/crash bandicoot

Just a small update this time:

  • Finally fixed those last bugs in the GTE, meaning the GTE is now 100% complete! (and im never touching it again after this). The bug that was keeping me from passing the last test (for MVMVA) was that i was missing a pair of parenthesis lmao.

  • Fixed that texture modulation issue - it turns out i was just parsing the command packets sent to the GPU incorrectly in some edge cases, but i ended up rewriting the whole polygon gpu packet parsing code.

You can take a look at the commits for this devlog here: https://github.com/Iamhere345/psx-emu/commits/main/?since=2025-09-07&until=2025-09-17

Image: crash bandicoot with correct texture modulation

Update attachment

its been ages since my last devlog, and I haven't really done a heap of work on my emulator bc of school but I've still made some decent progress. Most notably:

3D GAMES WORK AAAAAAA

Here's what I've actually done though:

  • after finishing RTPS/RTPT, all the other GTE instructions were fairly trivial and didn't take much time to write/debug. MVMVA is the second harder instruction besides RTPx, but I didn't have much trouble with it since the reason its hard is because it has a heap of hardware bugs which are all pretty well documented.

    • after finishing a few instructions I got Crash Bandicoot and Ridge Racer working. Crash worked perfectly, however Ridger Racer had this really strange bug where VRAM was getting overwritten by random solid-colour rects, corrupting the textures and making it look progressively worse the more you played it. I honestly have no idea what was causing this but eventually it fixed itself after I implemented some more GTE instructions.
  • Right now I have a more subtle bug where any game which uses texture blending (multiplying the texel with a gouraud shaded pixel basically) would make the colours look really wrong. After a lot of debugging i'm fairly certain this is a GTE issue not a GPU issue, but i'm still not sure whats actually causing it (although im still failing a few GTE tests so it could have something to do with that). You can see this in the attached video of Crash Bandicoot.

After I fix this colour bug im gonna start working on the SPU (Sound Processing Unit) which is supposed to be actually well-designed so it should be more fun than this awful GTE stuff lol.

I finally started work on the GTE, and it turns out it's a lot worse to emulate that I thought because:
<br/>
- Basically the only documentation is an appendix of a sony manual about using the GTE
<br/>
- the tests suck. One of them is closed source and doesn't tell you why you're failing (it also takes a billion years to run because it uses it's own software emulation of the GTE to test against) and the other one doesn't cover all the edge cases
<br/>
- it uses fixed point maths with different fractions for different registers / intermediary results and it isn't made clear which variables use what fractional bits.
<br/>
- it has undocumented quirks that you just have to figure out by trial and error or by looking at other emulators
<br/>
- it has hardware bugs
<br/>
- You have to emulate it's weird 'fast' division algorithm
<br/>

tl;dr i HATE the GTE and it SUCKS.

<br/>

Anyway so the reason it was taking me so long to start working on the GTE was because I was going to start by doing opcode 0x01 (RTPS which is used for perspective transformation), which just happens to be by far the harded instruction in the GTE. Once I moved to working on some easier opcodes like SQR (computes the square of a vector), OP (the mnemonic is a mistranslation - it computes the cross product of two vectors), and GPF/GPL (general purpose interpolation) I started getting the hang of how things worked on the GTE. Soon I had to move back to working on RTPS (because the tests make you test it really early on so you need it to work before testing the other opcodes), and even with my knowledge gained from doing easier opcodes it was still a massive pita has taken up like 90% of my time working on the GTE so far. It has a heap of quirks and edge cases, but after like a week of trying to get it working I had it passing most tests (it's still failing a flag test but i don't know why since the test doesn't tell you why it's failing).

<br/>

But after getting RTPS (and RTPT which is just RTPS repeated 3 times) into a mostly working state i'm starting to see 3D graphics. I still need to implement some more opcodes (most notably MVMVA or Multiply vector by matrix and vector addition) before 3D games start working, but I can see parts of the menu in crash bandicoot and the 3D background in castlevania, also some 3D homebrew for testing the GTE is starting to work now too.

Video: hello_cube_tex.exe from nolibgshelloworlds

I've just been working on more GPU stuff while I try and wrap my head around the GTE, so heres what I've done:
<br/>
- implemented texture blending / colour modulation. This means that textured polygons and rectangles can be coloured dynamically, which a lot of 3D games like crash bandicoot make extensive use of. It was a bit of a pain to get right since I had a bug where I was converting it from 24 bit colour to 15 bit colour wrong or something, and i'm still not sure if it's fully accurate, but it looks good enough on most test roms.
<br/>
- I now correctly set the semi-transparency of textured GPU primitives depending on whether or not bit 15 of the texel is set. This fixes the cursor in the bios menu being semi-transparent when it shouldn't be.
<br/>
- I fixed a really strange bug where rectangles moving off the edge of the screen had this weird wrapping effect (i don't really know how to explain it). It turns out that if a rectangle was slightly outside the drawing area i just wasn't render it at all, when the correct behaviour would be to only render the portion of it that was within the drawing area.
<br/>
Next I want to actually start working on the GTE, and I found some more documentation which might help with that.
<br/>
image: the benchmark.exe test rom demonstrating colour modulation in my emulator.

Update attachment

Not much has happened since my last devlog since I was on holiday for all of last week, but I've still made some progress:
<br/>
- Started work on the GTE (Geometry Transformation Engine). The GTE is the PS1's 3D maths co-processor, and it has a bunch of registers (64 iirc) and some instructions which do stuff like manipulating vectors, matrices, colours and light, as well as performing perspective transformations on vectors. It's pretty poorly documented and designed, which makes it a massive pain to emulate, so for now i've only implemented the registers (which were still a pain to get working). Once i get a few GTE instructions working i should be able to play 3D games.
<br/>
- implementing GTE registers (as well as reading and writing to them) actually fixed some crashes I was getting in Castlevania and Puzzle Bobble. It turns out both of these games were using an SDK function called SquareRoot12, which needed reading from GTE registers to work, otherwise it would crash trying to read unmapped memory.
<br/>
- I also implemented semi-transparency for the GPU, which was actually surprisingly easy, and made Megaman X4 look a lot better.
<br/>
- I also fixed a really annoying graphical bug where some quads (on the PS1 a quad is a rectangle made out of two polygon primitives) had like a chunk taken out of them, so there were strange triangle-shaped holes in some of the textures for some games. After hacking together a wireframe view for polygons I could see that for some quads had their vertices mixed up, which was causing them to have a 'butterfly' shape instead of a rectangle shape, causing parts of the texture to not be rendered. It turns out the issue was just that I was swapping the vertices around the wrong way when rendering the polygons, so it was a one line fix lol.
<br/>
image: Mortal Kombat II using my hacked-together polygon wireframe view (for some reason this game renders the left side of the screen using rect primitives and the right side with polygon quad primitives). You can see that some quads have a 'butterfly' shape with the triangle crossing over each other instead of having a rectangular shape like other quads.

Update attachment

I've made even more progress since the last devlog (and i really need to start doing shorter commits/devlogs lol), so instead of listing every change i'm just gonna give a general summary of whats happened (full details can be seen here: https://github.com/Iamhere345/psx-emu/commit/ff5a46be062c4e9e7de45d30b9ee7606d544dcc9).

  • A heap of games work now! This includes Megaman X4, Mortal Kombat II, Puzzle Bobble, and Castlevania: Symphony of the Night. Additionally Ridge Racer and Crash Bandicoot make it to the menus, but need the GTE (the PS1's 3D maths coprocessor) to make it ingame. Also Silent Hill and Driver are showing signs of life but still need some more work to get to the menus.

  • I managed to fix some pretty big CDROM bugs (which is why all these games work now when before they were getting stuck reading the same CD sector over and over again). I now properly handle reading the CDROM data FIFO (my previous implementation of this was causing the games to get stuck in the read loop), and fixed a bug where an extra interrupt was being sent after the pause command was sent to the CDROM.

  • I also figured out that i was decoding GPU control commands (GP1 cmds) completely wrong, and so once I fixed that I had to implement a heap of them. This also allowed be to un-stub the GPUSTAT register since uses the results from a lot of GP1 commands, however doing this seemed to make games freeze (?) so I ended up hardcoding it to 0x1C000000 again. On the GPU side I also implemented the drawing offset command, which fixed double buffering in a few games and also fixed the opening screens of Crash Bandicoot.

The last main bug i fixed was making it so timer IRQs are always fired, even if the IRQ flag is still set. I'm still not handling timer IRQs correctly, but this stops Crash Bandicoot from freezing on the first screen.

P.S i put a few more screenshots in the repository README since i can only put one here.

Update attachment

I've made a heap of progress since the last devlog, and now I can boot a heap of games!

There are still a lot of games that i've tested which hang reading the same CD sector over and over again, which is a very vague issue but I think might all be caused by the same problem so im going to look into that next.

Games that I've tested:
- Mortal Kombat II - works with minor graphical issues
- ridge racer - gets to the menus but crashes just before getting ingame
- puzzle bobble - gets to the menus but crashes just before getting ingame
- crash bandicoot - loads textures and shows the copyright screen, then hangs
- driver - hangs reading the same CD sector over and over again
- megaman X4 - hangs reading the same CD sector over and over again
- Castlevania Symphony of the Night - hangs reading the same CD sector over and over again
- Metal Gear Solid - hangs on a black screen, don't know what it's doing
- Gran Turismo 2 (Arcade) - crashes trying to read an MDEC (image decoder) register to play an FMV

Changes made:
- stub the SPU (sound processing unit) i.e. i handle reads/writes to SPU registers but nothing more than that.
- fixed a scheduler bug that broke the timers (i'm pretty sure this was the reason why most games weren't booting at all, and the fix was one line lol)
- implemented line and polyline GPU primitives (a polyline is just a series of lines sent one after another, but bc of the way i set up my GPU state machine it was a pita the implement)
- implemented / stubbed a few CDROM commands, which were necessary to get more games booting

So next im gonna try and fix that CD sector looping issue, but anyway heres a video of ridge racer working in my emulator:

Overhauled my UI using egui_dock to organise my debugging views into docking windows. Looks a lot better imo, and now i can see everything without having to constantly be moving windows around. (I would show what it looked like before but I can only upload one image)

Update attachment
Luke
Luke created a project
513d ago

psx-emu (PS1 Emulator)

emulator for the original Sony PlayStation (or PS1/PSX). Still a WIP, but can now run a decent number of games.

psx-emu (PS1 Emulator)
14 devlogs 2 followers Shipped
Luke
Luke joined Summer of Making
514d ago

This was widely regarded as a great move by everyone.