Commit Graph

1796 Commits

Author SHA1 Message Date
ser-pounce
89cdcbfda3
Decompile NO3 EntityUnkId15 & dedupe EntityUnkId15Spawner (#941)
- Decompile NO3 func_801C8C84
- Dedupe EntityUnkId15Spawner (+ some entity enum normalization)
2024-01-02 11:08:30 -05:00
ser-pounce
c55faf5994
Decompile NO3 func_801CC5A4 (#940) 2024-01-02 10:23:45 +00:00
Luciano Ciccariello
71b086e8b2
Add stage dummy (#939)
Last test app specific PR for a few days. This adds a dummy stage that
gets loaded by `InitStageDummy`. It does very similarly what the game
does by copying the exported stage functions into `g_api.o`. The new
entrypoint is now `InitRoomEntities`.

The dummy stage loads some assets from WRP. The stage layout and tileset
are loaded in-memory. I created a very barebone `RenderTilemap` to draw
the foreground without any scrolling implemented. I am not sure why the
HUD is only showing when entering in the menu and it's black.

There is a hack job in the dummy stage to skip the SEL overlay and ask
the game to load WRP. Choosing WRP is purely arbitrary as any stage but
SEL would result to the same behaviour.

This is a bit of a memory hog. I introduced a memory pool instead of
using `malloc` for the assets loaded dynamically. The dummy stage will
not stay here for long, so I do not find useful to optimise it.

<img width="263" alt="image"
src="https://github.com/Xeeynamo/sotn-decomp/assets/6128729/4c0c0ed9-ddca-4f5b-a35d-a3fe0f8ababa">
2024-01-02 09:22:44 +00:00
ser-pounce
d2be148d68
Decompile NO3 func_801CC6F8 (#938) 2024-01-02 00:56:41 +00:00
Luciano Ciccariello
0df33d1975
Texture render support (#934)
Technically unimpressive, but I had to go through quite a good amount of
changes. Here is the full changelog to make everything work:

* Ensure `ResetPlatform` is always called to avoid memory leaks
* Add `g_RawVram` to emulate the PS1 VRAM
* ~~The engine will load the optional file `disks/vram.bin`, a RAM dump
from an emulator~~
* SDL2 will create 256x256 textures on-the-fly whenever a specific tpage
is requested via `GetVramTexture`
* The function `GetVramTexture` caches the last called tpage to avoid
tanking the performance
* `GetVramTexture` for only renders 4bpp and 8bpp textures with their
specified palette
* Remove `SDL2_image` as the font is now loaded straight from the VRAM
* Calling `VSync` will call the set callback, which the game uses for
DMA operations
* `MyLoadImage` is not yet implemented, but it is a placeholder to then
interact with `g_RawVram`
* The menu font now uses the texture found in the VRAM
* Plugged a custom version of `LoadFileSim`
* The file `sim_pc.c` is similar to the original game's code but it is
used here to load files from custom paths
* Using F5, F6 or F7 can dump the VRAM content on-screen, respectively
in 16bpp, 8bpp and 4bpp

There are new graphical glitches on the font. In some occasions it
appears black. It seems to be related to a flag in `P_TAG.code`. I plan
to dig into it when I can render entities on screen to avoid potential
mistakes. The same problem is present for the first half of Alucard's
portrait. It seems to be related when a texture is transparent? 🤷

I am not sure why the font is completely corrupted when entering in the
Equip menu. It is hard to understand if I introduced any regression.
Maybe the glitch was always there but it was hidden since I was always
forcing the font texture to be rendered.

EDIT: Implemented `LoadImage`, `SaveImage` and `ClearImage`
2024-01-01 23:31:56 +00:00
ser-pounce
1c0debf74d
Decompile NO3 func_801CC820 (#937)
Surrounding code also seems to use the same entity struct
2024-01-01 16:28:02 -05:00
Luciano Ciccariello
8af8569e75
SEL func_801B78BC (#936)
Quick win. It is obviously inspired by #926 , so thanks @ser-pounce to
have decompiled that function!
2024-01-01 15:57:53 -05:00
ser-pounce
de2ca461a5
Dedupe ST func_8018D8F0 (#935)
- Decompile NP3 func_801CDF1C
- Tiny refactor
- Dedupe ST func_8018D8F0
2024-01-01 19:54:13 +00:00
ser-pounce
87835ffb04
Decompile NP3 func_801CDF1C (#933)
Previously attempted by @sonicdcer https://decomp.me/scratch/CMSl2.

I'm not sure the signature for func_801CDD80 is correct, which led me
down this rabbit hole. It matches, but there's a lot of ugliness going
on, I'm not sure if `arg1` has the correct type, or that `GH_Props` is
the right struct to access..
2024-01-01 19:42:16 +00:00
bismurphy
0513b639e4
Decompile RIC func_8016F198 (#928)
This one is pretty weird, there are a whole bunch of temp variables that
I couldn't figure out how to solve.

There are 8 blocks which set a variable, capped between 0 and an upper
limit (0xF0 or 0xFF). For the upper limit, I have created a `MIN()`
macro. I tried to make a `CLIP()` which would handle both limits in one
macro, but couldn't create one that would match.

Scratch here if anyone can improve things:
https://decomp.me/scratch/fY8js
2024-01-01 11:00:48 -05:00
ser-pounce
7aac720708
Decompile NZ0 func_801C0A3C (#932)
Already 99% complete by @sonicdcer and @Xeeynamo on decomp.me, match was
completed by copying func_801C090C.
2024-01-01 14:44:43 +00:00
Luciano Ciccariello
fcf49bfc06
SEL func_801B4C68 (#931) 2023-12-31 23:05:15 +01:00
Luciano Ciccariello
d599bad642
SEL func_801B2108 (#930)
99% similar to `func_800F99B8` from DRA. The only difference is that a
third parameter that sets `var_s4` is missing.
2023-12-31 21:28:04 +00:00
Luciano Ciccariello
d45cb9c8d3
Fix func_8011A870 (#929)
I was casually browsing this file and I found some potential
improvements for this function.
2023-12-31 15:48:00 -05:00
ser-pounce
1445e1a3b6
Decompile ST0 func_801B11E8 (#926) 2023-12-31 12:05:50 -05:00
Luciano Ciccariello
4b9db58076
Import cd data (#927)
and resolving some fake symbols
2023-12-31 15:55:32 +00:00
Luciano Ciccariello
322222adfe
Import LBA data (#922)
This is a historical W.I.P. that held me back due to some dirty bytes in
the US version. It is now done.

I renamed the file to `lba_stage.c` as I plan to add another file called
`lba_bin.c` right after this PR.

To quickly build the HD LBA, which is very different, I wrote a quick
script to duplicate and patch the US one:

```python
def s16(f):
    return int.from_bytes(f.read(2), byteorder='little', signed=False)

def s32(f):
    return int.from_bytes(f.read(4), byteorder='little', signed=False)
    
with open("disks/pspeu/PSP_GAME/USRDIR/res/ps/hdbin/dra.bin", "rb") as f:
    f.seek(0x3C50)
    for i in range(0, 0x50):
        print(f"0x{s32(f):04X}, 0x{s32(f):04X}, 0x{s32(f):05X}, 0x{s32(f):04X}, 0x{s32(f):04X}, 0x{s32(f):05X}, 0x{s32(f):04X},")
        s32(f)
        s32(f)
        s32(f)
        s32(f)
```

---------

Co-authored-by: sozud <122322823+sozud@users.noreply.github.com>
2023-12-31 15:44:56 +00:00
bismurphy
57a99f25a6
Decompile RIC func_8016E9E4 (#925)
This required an update to maspsx, so that update is also included as
part of this PR.
2023-12-31 15:08:02 +00:00
ser-pounce
bbf8be1e4b
dedupe FindFirstUnkPrim2 (#924)
Sorry for the unimaginative function name, not really sure what it's for
yet. Pulled into the existing header as these two functions always
appear together. Slightly refactored the function.
2023-12-31 14:55:12 +00:00
ser-pounce
315bb17310
Decompile ST0 func_801B0414 (#923)
Slightly ugly (including the return type), but it's the best of a bad
bunch of alternatives so far.
2023-12-31 14:24:38 +00:00
ser-pounce
456e076265
Dedupe DestroyEntity (#920)
Needs a little macro magic to work with DRA, unless there's a better way
of doing this?
2023-12-31 10:54:07 +00:00
ser-pounce
a46a70b251
Dedupe SetTexturedPrimRect (#921)
config/symbols.us.ric.txt change unrelated
2023-12-31 10:25:30 +00:00
sozud
437a970d6e
SpuVmSetProgPan (#919)
https://decomp.me/scratch/fimdr
https://decomp.me/scratch/SNovV
2023-12-31 09:34:45 +00:00
bismurphy
c41176bfc5
Decompile DRA EntityStopWatchExpandingCircle (#918)
Realized this matches a function in RIC, so this PR decompiles the DRA
version, and also renames the RIC version to match.
2023-12-30 14:29:02 -05:00
bismurphy
cfd20eb437
Decompile RIC func_80162870 (#917)
Keeping them coming, nothing notable about this one.
2023-12-30 13:25:19 -05:00
bismurphy
bc2da02023
Decompile RIC func_80161FF0 (#916)
Some entity, don't know what. There seem to be a lot of entities that
just use 7C and 7E from the `ext`, might be something we think about
unifying in the future.
2023-12-30 13:16:09 -05:00
bismurphy
e649812bd6
Decompile RIC func_8016147C (#915)
Similar to an existing DRA function, which is noted.
2023-12-30 11:36:45 -05:00
sozud
b3160407b5
_spu_FiDMA (#914)
Trying the remaining one from this again
https://github.com/Xeeynamo/sotn-decomp/pull/859
https://decomp.me/scratch/ergMa
2023-12-30 11:24:22 -05:00
sozud
2d2eb200f1
SsSetTickMode, add jpt splits (#911)
https://decomp.me/scratch/N9Af7
2023-12-30 08:57:44 +00:00
Luciano Ciccariello
22c86430ea
Add File specific funcs (#898)
I am not sure if we want to use this pattern. Here I am proposing to
wrap functions to open files and read the entirety of a file.

The objective is to avoid performing sanity checks for `fopen`, `fread`
and `malloc`, other than ensuring allocated resources are correctly
de-allocated on both happy and unhappy paths.

How it works is the first parameter is always the callback, while
starting from the second are all the parameters necessary to instantiate
and allocate the resources to be passed to the callback.
2023-12-30 08:54:50 +00:00
bismurphy
00269c82fc
Decompile RIC func_80160FC4 (#913)
Credit to @ser-pounce for some of the variable names here; apologies to
them for the overlap on decompiling the same function.
2023-12-29 23:32:32 -05:00
bismurphy
65a9a413bf
Decompile RIC EntityEntFactory (#912)
Found this function in RIC, it's very similar to the one in DRA, which
is nice.

Patterns of zeros in the rodata indicated that this should be the start
of a new file, which also makes sense since CreateEntFactoryFromEntity
comes with it.

RIC has its own array of blueprints, I'll probably add that to the splat
later on but that seems like material for a separate PR. For now we
focus on the entity function.
2023-12-29 20:09:52 -05:00
sozud
abad025e80
Fix svm_cur, add some symbols (#910) 2023-12-29 19:57:34 +00:00
sozud
d34781137d
_SsContModulation _SsContPortaTime (#907)
https://decomp.me/scratch/V1zKk
https://decomp.me/scratch/XygVI
2023-12-29 11:16:03 -05:00
bismurphy
69e4d77fd4
Decompile RIC func_8015DBB0 (#909)
Looks like a lot of physics, not sure exactly what this does. But it
finishes out the 21250.c file, so that's nice!
2023-12-29 15:24:34 +00:00
sozud
34d99310f8
_spu_reset (#906) 2023-12-29 15:22:16 +00:00
bismurphy
40b8396301
Decompile RIC func_8015D678 (#908)
This appears to control Richter using an item crash.

We add an enum for the subweapon IDs. This should be useful in other
places but for now makes the switch much more readable.
2023-12-28 18:18:05 -05:00
bismurphy
2ce4133bfc
Decompile RIC func_8015D3CC (#905)
No knowledge of the purpose of this function. At this point I'm just
going through RIC sequentially.
2023-12-28 14:12:26 -05:00
bismurphy
bc13f83e48
Refactor g_Player.D_80072F00 (#904)
Loops in EntityAlucard and UpdateEntityRichter indicate that these 16
elements of g_Player are an array of 16 values. The known ones appear to
be player status effect timers.

While those functions have a long-standing issue preventing them from
matching, they provide enough evidence to suggest that we should make
this change. I have changed all existing uses, and changed the symbols
so that any remaining non-decompiled functions will use the proper form.

It would probably be beneficial to make an enum for the 16 elements of
this new array, but I'll hold off on that for now until we can identify
the purpose of more of them.

---------

Co-authored-by: Luciano Ciccariello <Xeeynamo@users.noreply.github.com>
2023-12-28 08:49:07 +00:00
sozud
2308066251
SsUtSetVagAtr (#902)
https://decomp.me/scratch/X8he9
2023-12-28 03:14:55 -05:00
Julien Augugliaro
9a5fe7cea1
Decompile DRA func_8010DBFC (#903)
Function looks like function `u32 UpdateAnim(s8* frameProps, s32*
frames)` without any value returned.

Next step will be `func_8010DA70` as it is used with it.

scratch : https://decomp.me/scratch/Ib0tn
2023-12-28 08:00:55 +00:00
sozud
9796b148ce
SpuClearReverbWorkArea (#901)
https://decomp.me/scratch/KAEiS
2023-12-28 07:55:26 +00:00
bismurphy
53f98aab5e
Decompile RIC func_8015C6D4 (#899)
This one has a corresponding DRA function. I believe these relate to the
fading shadows that appear behind the player, but I'm not confident
enough about that to go ahead and rename things. For now, it's
decompiled at least.
2023-12-27 20:00:10 -05:00
Luciano Ciccariello
e624edd999
Reduce _MSC_VER footprint (#896)
Reduce the amount of `#ifdef` by abstracting platform specific code into
ad-hoc C files that can be linked and swapped.

I trimmed down `libapi.c` and used the `My`/`my_` pattern for those
specific PSX API calls. The new `plat_unix.c` contains the usual code,
while `plat_win.c` contains placeholder functions waiting for an
implementation. I have no rush to do so because I have yet to test if
the unix version works.

I removed from `sotn.c` and `libcard.c` any reference to SDL, which is
now self-contained in `sdl2.c`.
2023-12-27 11:26:24 -05:00
bismurphy
4c0b9d15a3
Decompile RIC func_8015B898 (#897)
Another function, nothing super special. Not aware of any DRA
equivalent.
2023-12-27 15:34:48 +00:00
sozud
5c124e0a56
SsSeqCalledTbyT (#895) 2023-12-27 09:32:53 +00:00
Luciano Ciccariello
ea85ddf75f
Import menu strings for US (#890)
I had the suspect menu strings were part of a string of arrays since a
while. So I come up with a `g_MenuStr[]`, which removed the need of many
fake symbols. I did not yet come with a bunch of `#define`s to resolve
some magic numbers. Luckily you can guess which string is which from the
context of the function. Resolving the HD strings might give me more
clues on how to come up with good defines.

I decided to go for the route of having a `lang_us.c` and a `lang_jp.c`
for the sake of maintaining things simpler. This is also due to the fact
the HD build orders the japanese strings in a different way, making
things a bit harder. Any modder can just come up with their own
`lang_XX.c`, translate the menu in the language they want and just link
it, without touching the original files.

For the test app things were tricky. I've been debating how to implement
it as SOTN-encoded strings are not pre-encoded on compilation time like
the PSX toolchain does. Instead they are burnt into the executable as
UTF-8 characters. Instead of encoding them on-the-fly in `MenuDrawChar`,
I decided to re-use `AnsiToSotnMenuString` to pre-encode all the strings
and re-route each `g_MenuStr` pointer to the converted strings. This is
both efficient at runtime and prevents to modify the existing matching
code. Now the menu looks amazing.

I thought this was going to be much harder to do. I ended up doing
incremental steps in each commit to ensure having healthy checkpoints in
case things were going south. The tool ` ./tools/sotn-str.py parse
disks/us/DRA.BIN 0xOFFSET` saved me sooo much time. But we need to tweak
it to deal with Japanese characters.
2023-12-27 09:31:39 +00:00
bismurphy
c011a3c461
Decompile RIC func_8015C4AC (#894)
Extremely similar to a DRA function, which is noted in the code.
2023-12-27 09:30:58 +00:00
sozud
4791b03c89
Windows build with cmake (#889)
This adds cmake and a windows build to the CI. I haven't tested the
result, just got it building. I had to make quite a few changes since
MSVC has a number of differences compared to GCC. I added two cmake
modules to find sdl2 and sdl2_image from here
https://github.com/aminosbh/sdl2-cmake-modules

The dirent stuff is just `#ifdef`ed out for now since I think it's
unused?

I'm keeping the Makefile.pc for the moment until this is more proven. I
wasn't able to figure out how to add -fsanitize=address for some reason
to gcc/clang builds, open to suggestions there. Otherwise I think the
cmake build is more or less the same as the Makefile one.
2023-12-27 09:24:00 +00:00
ser-pounce
440db77cf2
Decompile RIC func_8015FEA8 (#893)
99% copied from DRA func_80119F70, but cannot be deduped due to subtle
differences.
2023-12-26 22:48:55 -05:00