fgsfdsfgs / sm64-port

PS2, PS3, OG Xbox and DOS ports of sm64-port.
https://discord.gg/7bcNTPK
242 stars 38 forks source link

PS1 port #69

Open oitofelix opened 2 years ago

oitofelix commented 2 years ago

Is it doable? I'd like to find out and possibly work on it. Any preliminary/practical suggestion or guidance?

oitofelix commented 2 years ago

By the way, I have the PSn00bSDK and the no$psx emulator/debugger working and its PSX programming specs at hand.

fgsfdsfgs commented 2 years ago

Theoretically yes, the hardware can probably handle it. You'll have to rework the entire level/segment loading system and separate resources into per-level packages, convert all the display lists into something more fitting for the PS1 GPU and rewrite large chunks of the renderer, all while dealing with the fact that the PS1 has no floats.

oitofelix commented 2 years ago

Sounds challenging. To get me started, let's break it into manageable chunks. How about getting that Mario face intro demo building and running first? I'm new to the sm64 code base. Any pointers on how I can isolate that part and its hardware-dependent interface, so I can begin to study how to port it? Any hints on how to setup the build system to use the SDK, in case that's something not that trivial/straight forward, are welcomed as well. :)

fgsfdsfgs commented 2 years ago

That would seem logical, but the Mario face demo (goddard) is completely separate from the rest of the game and uses its own code for pretty much everything, because it was basically tacked onto the game from a separate demo program or something. So it won't actually matter much in the long run, other than getting yourself used to the kind of problems you would face. It would be wiser to completely disable it, which can be done but I don't know how exactly. For the build system, you would have to modify how textures, models and levels are extracted, because you'll probably have to convert them into forms more convenient for the PS1. You might have to ask the original decompilation team for details on how exactly all of that stuff works, I'm mostly familiar with the "PC port" part of things, which you won't even really need for this.

oitofelix commented 2 years ago

For the build system, you would have to modify how textures, models and levels are extracted, because you'll probably have to convert them into forms more convenient for the PS1. [...] I'm mostly familiar with the "PC port" part of things, which you won't even really need for this.

Was this the case for the PS2 port? Do you think looking into that would give me a head start? Who was mainly responsible for that specific port?

fgsfdsfgs commented 2 years ago

The PS2 port did not require any fundamental changes, unlike a potential PS1 port. Like all the other ports in this repo it is based on the PC port. The entirety of the game code (including the loading and texture/model/whatever formats) in it is pretty much intact, I mostly changed the "PC renderer" part (src/pc/*) and other platform specific stuff. This is because the PC port of SM64 lets the game run pretty much like it would on an N64, during which it forms N64 display lists like it would on the N64, which are then processed by the PC renderer essentially the same way as they would be on a high level emulator. PS2 can handle the same approach just fine, which is exactly what I did. Of course rewriting the game to render natively would improve performance though.

oitofelix commented 2 years ago

PS2 can handle the same approach just fine, which is exactly what I did.

I see. The PS1 probably can't afford that overhead.

fgsfdsfgs commented 2 years ago

You can try, but you will still have to replace all float usage (the end form of the display list commands already only uses fixed points though, I think) and the loading system at the very least. In the original game there's a segment system that swaps a bunch of data into RAM from ROM on level change, but the PC port kind of does away with that, so everything is in RAM at all times and all resources are just packed into the executable, kind of like they would be packed into a ROM image. Obviously this won't do on a PS1.

By the way, if you need it, you can find the updated nocash specs here, PsyQ docs here and general help at the PSX-DEV Discord.

oitofelix commented 2 years ago

Thanks for the links and guidance. I plan to make it initially run with as few changes as possible and then improve from there. Right now I'm sorting out the build process using the mipsel-none-elf toolchain provided by PSn00bSDK, irregardless of implementation.

oitofelix commented 2 years ago

I managed to complete the build process using PSn00bSDK, commenting out all the PS2 platform specific code. For some reason the resulting sm64.us.f3dex2e.elf binary is only 13KB. Any idea why? The complete build log (after a make clean) is attached.

image

build-log.txt

fgsfdsfgs commented 2 years ago

Probably because of -gc-sections. If the compiler thinks something is unreferenced, it's going to nuke it. And it probably thinks everything is unreferenced for whatever reason.