Commit Graph

150 Commits

Author SHA1 Message Date
nmlgc c876216c1d [Maintenance] Remove master.lib's original master.h 🎉
My repo will never include all of master.lib anyway, as explained in
https://rec98.nmlgc.net/blog/2020-11-03.
That gets me a median build time of 27 seconds for the entirety of
ReC98 on my system, just as estimated in that same blog post. And we're
far from done with #include optimizations…

Part of P0133, funded by [Anonymous].
2021-01-30 19:37:41 +01:00
nmlgc eeb4e7ebfa [Maintenance] [th01/th02/th03] Compile the ZUN Soft logo animation as C++
This might have almost been the case that justified making master.hpp
compatible with C translation units… but even this one would like to
use the template functions from th01/math/vector.hpp.

Part of P0133, funded by [Anonymous].
2021-01-30 19:22:12 +01:00
nmlgc 72c32c8c9c [Maintenance] [th02] Compile more C translation units as C++
Everything that uses input and master.lib graphics functions.

Part of P0133, funded by [Anonymous].
2021-01-30 19:19:50 +01:00
nmlgc a186074af3 [Separate translation units] [th01] .PTN, .GRP, and .GRZ formats
Since I'd still prefer to not use include guards *and* to have that
standalone .GRZ viewer, these would have actually caused somewhat of
an issue with the upcoming final stretch of the master.hpp transition.

Part of P0133, funded by [Anonymous].
2021-01-30 19:17:16 +01:00
nmlgc e4eed85c44 [Separate translation units] [th04/th05] Low-level input (undecompilable)
Reason: Manual "tail call optimization" of input_reset_sense(), with
execution falling through to input_sense() immediately below.

Part of P0133, funded by [Anonymous].
2021-01-30 19:11:01 +01:00
nmlgc 6e91c4f99a [Decompilation] [th05] input_reset_sense_held(), input_wait_for_change()
Nope, not keeping this in ASM just because of some function calls
either.

Part of P0133, funded by [Anonymous].
2021-01-30 18:26:34 +01:00
nmlgc 4229054137 [Decompilation] [th05] snd_bgm_measure(), snd_delay_until_measure()
Umm… but this can't be in the same translation unit as frame_delay(),
because OP.EXE has cdg_put_nocolors() inbetween, which means we'd have
to compile it twice.

What probably happened there: ZUN originally wrote this in C when
frame_delay() was still next to it, then generated ASM from it,
tinkered with that, and ultimately only linked that ASM into the final
game, with the NOPCALL still in there. That might very well be the one
temporary NOPCALL workaround we can never get rid of…

Oh well, at least we got lucky with the padding, and can keep the
cdg_put_nocolors() decompilation from the last commit.

Part of P0133, funded by [Anonymous].
2021-01-30 18:23:03 +01:00
nmlgc c8160b9f94 [Decompilation] [th05] .CDG: Non-color blitting
And this is how you make code less undecompilable by improving your
pointless micro-optimizations to use more registers instead of
self-modifying code. Worth it if only to get rid of the branches in
TH04's undecompilable ASM implementation.

Part of P0133, funded by [Anonymous].
2021-01-30 18:20:44 +01:00
nmlgc 045450c788 [Decompilation] [th03] .CDG: Loading and freeing
Completes P0132, funded by [Anonymous].
2021-01-05 22:17:48 +01:00
nmlgc c12f9ea5f6 [Decompilation] [th03] game_exit_from_mainl_to_main()
Stupid one-off functions deserve stupid names…

Part of P0132, funded by [Anonymous].
2021-01-05 22:16:19 +01:00
nmlgc 3f61342898 [Decompilation] [th03] graph_putsa_fx()
Part of P0132, funded by [Anonymous].
2021-01-05 22:08:56 +01:00
nmlgc f539cca15d [Decompilation] [th03/th04] snd_delay_until_measure()
Part of P0132, funded by [Anonymous].
2021-01-05 21:56:57 +01:00
nmlgc cd4f94736a [Decompilation] [th03] input_wait_for_ok_or_measure()
… well, unless you put the call at the beginning of the loop.

Part of P0132, funded by [Anonymous].
2021-01-05 21:54:02 +01:00
nmlgc 3bf078b68c [Separate translation units] [th02/th03/th04] pi_load()
Part of P0132, funded by [Anonymous].
2021-01-05 20:01:44 +01:00
nmlgc c8fa3311b1 [Separate translation units] [th02] Unaccelerated page 1→0 rectangle blitting
Not using the EGC, because we gotta go slow in the main menus…?

Part of P0132, funded by [Anonymous].
2021-01-05 19:55:42 +01:00
nmlgc a1653146da [Separate translation units] [th02] 2D vector functions
Part of P0132, funded by [Anonymous].
2021-01-05 19:51:41 +01:00
nmlgc 39aa257a5d [Decompilation] [th03/th04] pi_put_quarter_8()
Part of P0132, funded by [Anonymous].
2021-01-05 19:47:12 +01:00
nmlgc dd7e200f3b [Separate translation units] [th02] .PI blitting
Part of P0132, funded by [Anonymous].
2021-01-05 19:34:59 +01:00
nmlgc 8580251c06 [Separate translation units] [th02] snd_kaja_interrupt()
Part of P0132, funded by [Anonymous].
2021-01-05 19:33:37 +01:00
nmlgc b9c24cf931 [Separate translation units] [th02] snd_delay_until_measure()
How was this game even *built*, originally, if it uses *both* a common
shared set of library functions *and* obviously copy-pasted and
separately compiled versions of some of these functions?

Part of P0132, funded by [Anonymous].
2021-01-05 19:32:18 +01:00
nmlgc aac0108c63 [Separate translation units] [th02] Sound effect playback (undecompilable)
Reason: Same as hflip_lut_generate() – wants to be word-aligned, and
the function before it has an odd length :(

Part of P0132, funded by [Anonymous].
2021-01-05 19:29:10 +01:00
nmlgc 52fdb33d1d [Separate translation units] [th02] frame_delay()
Part of P0132, funded by [Anonymous].
2021-01-05 19:23:31 +01:00
nmlgc b4d500b2de [Decompilation] [th01] Bosses: Generic no-op callback
Made truly generic by its use in both the upcoming boss collision
handling, as well as some SinGyoku pellet spawning function.

Part of P0130, funded by Yanga.
2020-12-18 01:38:46 +01:00
nmlgc 64f872e5c5 [Decompilation] [th01] Difficulty-based value selection
And with that, TH01 is pushed over the 50% completion mark! 🎉

This time, it's only YuugenMagan who gets no own copy. Giant RE% gains
from all these calls, but let's hope I don't regret already decompiling
this one for all bosses. It's not quite at the beginning of SinGyoku's,
Mima's, and Elis' code segment, after all…

Part of P0130, funded by Yanga.
2020-12-18 00:59:41 +01:00
nmlgc aaea18aa8f [Decompilation] [th01] Retrieving and setting the default boss palette
The placement at the beginning of Kikuri's code segment makes you think
this is only used for the barely noticeable white-in effect during
Kikuri's entrance animation. It's also used to periodically reset boss
sprite colors during the flashing effect after getting hit by the Orb,
though.

Part of P0130, funded by Yanga.
2020-12-18 00:55:21 +01:00
nmlgc 73f62a5ba2 [Decompilation] [th01] Stage objects: Background allocation and blitting
Continuing the good error handling from the .PTN functions they're
based on… if only its sole caller actually cared.

Also: A sort-of limit of 102 objects per stage, just because someone
didn't use huge pointers where they would have been necessary…
:tannedcirno:

Part of P0128, funded by Yanga.
2020-12-01 00:34:18 +01:00
nmlgc dc65b59dcc [Decompilation] [th05] frame_delay()
Finishing this push with another highly questionable one… Let's hope
that the port developers will certainly appreciate that they just have
to remove the weirdness here, and not mess with defining entirely new
functions in C land.

Completes P0127, funded by [Anonymous].
2020-11-16 20:01:36 +01:00
nmlgc 7897bf166f [Separate translation units] [th04/th05] .CDG: Loading and freeing
Undecompilable again. The loading functions have these *_noalpha()
variants that simply set a global variable and fall through to the
regular functions, while cdg_free() has its first `PUSH DI` instruction
after the first expression we'd be decompiling. cdg_free_all() *could*
be decompiled… but would also require _FLAGS trickery, and it's simply
not worth starting a translation unit for one such small function.

Part of P0127, funded by [Anonymous].
2020-11-16 20:01:35 +01:00
nmlgc 00f177e196 [Maintenance] [th03] Remove the input mode and delay function disassembly
MAIN.EXE now also caught back up with the decompilation.

Part of P0127, funded by [Anonymous].
2020-11-16 20:01:35 +01:00
nmlgc 8835d59eda [Build] [th03] Keep hflip_lut_generate() in ASM due to alignment issues
Nooooo, gotta throw away that decompilation for the stupidest of
reasons :( Turns out that a function may also be "undecompilable" if
the original code layout places it at a word-aligned address, but the
last byte of the previous function in just one of the original binaries
(TH03's MAIN.EXE, in this case) also lies at a word-aligned address.
There's simply no way to enforce per-function word alignment in Turbo
C++ alone. You *could* fake it with `#pragma codestring`, but of course
that won't work for functions that are part of the SHARED segment, and
where the alignment previously would have been correct. Conditionally
emitting that codestring would work, but then we'd also have to compile
that translation unit at least twice.

Now, I could have created a dummy .ASM file that just contains a single
zero-length but word-aligned SHARED segment, which could be placed
anywhere on the link command line where word alignment is needed… but
the decompilation of this function was a mess anyway, and probably
helped nobody.

Part of P0127, funded by [Anonymous].
2020-11-16 20:01:34 +01:00
nmlgc 5965930bd0 [Decompilation] [th03] .MRS: Persistent horizontal flipping
Another function consisting almost entirely of inline ASM. Still worth
it though, if only to save us from duplicating any declarations in ASM
land.

Part of P0126, funded by [Anonymous] and Blue Bolt.
2020-11-16 20:01:31 +01:00
nmlgc 08a09aabb2 [Reverse-engineering] [th03] .MRS: Bitplane pointers
Part of P0126, funded by [Anonymous] and Blue Bolt.
2020-11-16 20:01:26 +01:00
nmlgc 6c22af7e83 [Build] [th01] Only compile shared single-file translation units a single time
Which gets rid of 13 redundant translation units. Definitely a good
start, before I figure out how to best handle the more complicated
cases.

(Maintenance mode commit)
2020-11-04 14:47:52 +01:00
nmlgc f6a3246071 [Reverse-engineering] Enabling and disabling the EGC
Which involves temporarily enabling a GDC mode change bit.

Completes P0125, funded by [Anonymous].
2020-11-02 23:42:04 +01:00
nmlgc 056b1c77c1 [Decompilation] [th04] Player character and shot type selection menu
Significantly more complex than the single menu in TH05!

Completes P0124, funded by [Anonymous] and Blue Bolt.
2020-11-02 22:41:51 +01:00
nmlgc 10666131ec [Decompilation] [th01] Reimu's animations: .BOS load function
Part of P0123, funded by Yanga.
2020-10-13 21:15:19 +02:00
nmlgc 61559859e3 [Decompilation] [th01] Shootout lasers: Spawn function
Part of P0122, funded by Yanga.
2020-10-06 14:16:40 +02:00
nmlgc eb89330f64 [Build] [th01] Move the -Z and -3 options onto the command line
Deactivating them is the exception, not the norm.

Part of P0122, funded by Yanga.
2020-10-06 13:27:33 +02:00
nmlgc 60ee6e94fc [Decompilation] [th01] 32×32 square inversion on a single bitplane
The main effect behind the discoloration seen in the bomb animation,
as well as the exploding squares at the end of Kikuri's and Sariel's
entrance animation.

Single-function segments are lovely, by the way!

Part of P0121, funded by Yanga.
2020-09-28 13:05:07 +02:00
nmlgc 453dd3ca7e [Decompilation] [th05] Starting the game
And that's the intended way to play back the hidden DEMO5.REC. Unlock
the Extra Stage with all 4 characters, then hold the left and right
arrow keys in the main menu while waiting the usual demo replay.

For a recording of that replay, see

	https://www.youtube.com/watch?v=iP2ywlW2u4U

Completes P0119, funded by [Anonymous] and -Tom-.
2020-09-21 15:00:44 +02:00
nmlgc 3c27fbc3bd [Decompilation] [th05] Player character selection menu
The TH04 one might have the same function structure, but the only thing
that's actually identical in both games is the picture darkening loop.

Part of P0119, funded by [Anonymous] and -Tom-.
2020-09-21 15:00:05 +02:00
nmlgc 791d6d6085 [Build] [th04/th05] 16-bit: Rebuild ZUN.COM by default
Shoutout to Egor, who already implemented the necessary wrappers in
2018, which means that I don't have to spend a push on that. 🙂

Part of P0117, funded by [Anonymous].
2020-09-16 22:30:56 +02:00
nmlgc c5852610f6 [th05/gjinit] Initial state
And with that, we finally dumped every single PC-98 Touhou binary!
Since it'd be overkill to merge bmp2arr into the re-baseline branch
though, we also have to start out with the raw image bytes here.

Part of P0117, funded by [Anonymous].
2020-09-16 22:29:55 +02:00
nmlgc 9695c8d277 [th05/memchk] Initial state
No libc anymore, yet still no memory freeing…?

Part of P0117, funded by [Anonymous].
2020-09-16 22:29:35 +02:00
nmlgc 90b7ace180 [th04/memchk] Initial state
Needlessly linked with TCC rather than TLINK, adding almost 4 KB of
completely unnecessary libc startup code.

Or maybe not, since ZUN doesn't free the allocated memory himself, but
relies on libc to do that?

Part of P0117, funded by [Anonymous].
2020-09-16 22:20:34 +02:00
nmlgc 197202d8ee [th05/zuninit] Initial state
On the surface, Version1.02 of the `INTvector set program` seems to
be largely the same as Version1.01, just with fancier instructions,
some redundancy removed, and some slightly different wording in the
playful messages… or is there more to it? Stay tuned!

Part of P0117, funded by [Anonymous].
2020-09-16 22:17:18 +02:00
nmlgc f54cd0fe95 [th04/zuninit] Initial state
Yup, it's finally the right time to properly rebuild ZUN.COM. While
all of these small binaries would still need some RE attention, putting
in the few minutes to make them position-independent right now is
definitely worth it. Adding them to the PI calculation on the website
would take much longer 😅

Part of P0117, funded by [Anonymous].
2020-09-16 22:16:49 +02:00
nmlgc 03048c318d [Decompilation] [th04/th05] Cutscenes: Text blending
Completes P0116, funded by [Anonymous] and Lmocinemod.
2020-09-12 12:09:31 +02:00
nmlgc 4e6bedf20d [Decompilation] [th05] Staff roll: Space window coordinates
Part of P0115, funded by Lmocinemod and Blue Bolt.
2020-09-12 11:21:44 +02:00
nmlgc 967bb8b633 [Decompilation] [th03] Input mode and delay functions
Nice to see that Borland C++ optimizes bit-tests to cover just the high
or low byte of a word if possible, and that these don't have to be
two-byte structures after all.

Completes P0114, funded by Lmocinemod.
2020-09-07 21:18:40 +02:00