Commit Graph

180 Commits

Author SHA1 Message Date
nmlgc a2e515534c [Translation unit catch-up] [th04] Low-level input
Part of P0136, funded by [Anonymous].
2021-03-20 02:36:38 +01:00
nmlgc 16899204df [Decompilation] [th04/th05] Sound effect playback
At least it's decompilable in these games, and quite nicely so!

Part of P0136, funded by [Anonymous].
2021-03-20 02:36:38 +01:00
nmlgc a935a8b1bd [Translation unit catch-up] [th04] egc_copy_rect_1_to_0_16()
Time to delete stuff!

Part of P0136, funded by [Anonymous].
2021-03-20 02:36:36 +01:00
nmlgc 8164c71d22 [Decompilation] [th04/th05] bgimage_snap(), bgimage_put(), bgimage_free()
Eh, REP MOVSD is used too inconsistently across the games to justify
replacing these macros with an `inline` function. Still can use a
custom one here to make the register usage a bit more explicit, though.

Part of P0136, funded by [Anonymous].
2021-03-20 02:36:36 +01:00
nmlgc 85019517e2 [Separate translation units] [th04/th05] cdg_put_8() (undecompilable)
Reason: Self-modifying. -.-
The TH05 version *might* be decompilable into a mess. Don't have time
for that right now, though.

Part of P0136, funded by [Anonymous].
2021-03-20 02:36:34 +01:00
nmlgc 46359e643e [Translation unit catch-up] [th05] game_exit()
Part of P0136, funded by [Anonymous].
2021-03-20 02:36:32 +01:00
nmlgc c6c724ac21 [Decompilation] [th03] pi_put_interlace_8()
Obvious copy-pasta…

Part of P0136, funded by [Anonymous].
2021-03-20 02:17:08 +01:00
nmlgc 1ad64dc514 [Translation unit catch-up] [th03] Sound effect playback
Part of P0136, funded by [Anonymous].
2021-03-20 02:17:07 +01:00
nmlgc 0929d91e50 [Translation unit catch-up] [th03] snd_kaja_interrupt()
Part of P0136, funded by [Anonymous].
2021-03-20 02:17:05 +01:00
nmlgc 0263439fac [Decompilation] [th04/th05] vector1_at(), vector2_at()
Almost undecompilable, until you remember that you can inhibit the
optimization of keeping a function parameter in a register by having an
`inline` function take a reference. Yet another function that wouldn't
have decompiled that nicely if we had restricted us to C…

Part of P0136, funded by [Anonymous].
2021-03-19 23:29:26 +01:00
nmlgc 252c13d383 [Decompilation] [th05] Music Room piano (decompilable functions)
If anything, these decompilations of barely decompilable functions can
at least indicate that I tried. 🤷 Nice __fastcall abuse though, which
allows us to least formalize *some* of the implicit state passed
between those functions.

Completes P0135, funded by [Anonymous].
2021-03-19 23:26:16 +01:00
nmlgc 152ecaa496 [Separate translation units] [th05] Music Room piano (undecompilable functions)
Reasons:
• piano_fm_part_put_raw(): SI register referenced and not saved on
  the stack
• piano_current_note_from(): Would be decompilable… into a mess.
  Not worth adding a separate translation unit just for it.
• piano_part_keys_put_raw(): DI register saved before the SI register
• piano_pressed_key_put(): DI register referenced and not immediately
  saved on the stack
• piano_label_put_raw(): SI and DI registered referenced and not saved
  on the stack
• grcg_setcolor_direct_seg1_raw(): Let's procrastinate this one until
  we have to reference all of these instances in C land.

And we could have even emitted that PIANO_KEY_PRESSED_TOP pixel data
into the code segment, by using `#pragma option -z` to give identical
names to both the code and the data segment. At least we can decompile
the first two functions here.

Part of P0135, funded by [Anonymous].
2021-03-19 23:23:06 +01:00
nmlgc f35b051edd [Separate translation units] [th04/th05] bgimage_put_rect() (undecompilable)
Reason: Self-modifying. -.-

Part of P0135, funded by [Anonymous].
2021-03-19 23:19:48 +01:00
nmlgc 01c92da1ac [Decompilation] [th05] snd_load()
A decompilation of ZUN-written ASM that was almost worth it, for once!
Too bad that those aren't the <string.h> intrinsics that the
Wolfenstein 3D disassembly hinted at, though.

Part of P0135, funded by [Anonymous].
2021-03-19 19:22:57 +01:00
nmlgc 903f5b55de [Separate translation units] [th05] snd_kaja_interrupt() (undecompilable)
Reason: Pascal calling convention with function parameters but no stack
frame.

Part of P0135, funded by [Anonymous].
2021-03-19 19:16:01 +01:00
nmlgc a6eed55258 [Decompilation] [th05] pi_put_masked_8(), pi_put_quarter_masked_8()
Completes P0135, funded by [Anonymous].
2021-02-21 14:04:52 +01:00
nmlgc 69111bd862 [Separate translation units] .PI: Row loop for masked blitting (undecompilable)
Reason: Pascal calling convention with function parameters but no stack
frame. Theoretically we can __emit__() everything inside this function,
but there's no way we can get a `RETN 8` this way. Oh, and it also
accesses SI and DI without backing them up to the stack.

And thanks to TLINK apparently not reporting fixup overflows when
segments are small enough (?), it took quite a while to get that CALL
correct and not weirdly offset by 32 bytes. 😕

Part of P0134, funded by [Anonymous].
2021-02-21 14:04:51 +01:00
nmlgc a064267a0b [Build] Use Borland's extended .OBJ dictionaries to speed up linking
> try to debug weird linker error
> find performance secret sauce

Removes roughly 1 second from the build time of the full repo!

Part of P0134, funded by [Anonymous].
2021-02-21 14:04:51 +01:00
nmlgc ffcc46d32f [Decompilation] [th05] pi_put_8(), pi_put_quarter_8()
> assigning to the DI register immediately before a CALL
Yeah, no amount of comma operator trickery can get *that* out of this
compiler. Also, these TH05 .PI functions are the only place in PC-98
Touhou with a `IMUL DI, imm8` instruction, which is impossible to get
out of Turbo C++'s built-in assembler.
Well, at least the `if` branches decompile somewhat nicely.

Part of P0134, funded by [Anonymous].
2021-02-20 23:50:03 +01:00
nmlgc 2777bae55b [Separate translation units] [th05] pi_free() (undecompilable)
Well, it *would* have been decompilable, but that ridiculous placement
of the nullptr assignment would have forced the entire function call to
be spelled out in inline ASM, verbatim. No amount of comma operator
trickery would have generated the same instructions either. And for a
function this small and obvious in what its decompilation *should* be,
it really defeated the purpose of adding a separate translation unit…

Part of P0134, funded by [Anonymous].
2021-02-20 23:50:02 +01:00
nmlgc 7a44adf8d0 [Maintenance] Use the C++ resdata_*() wrappers in all ZUN.COM sub-binaries
Getting us completely macro-free there… even though it did require a
separate version of those functions if the ID is a pointer.

Part of P0134, funded by [Anonymous].
2021-02-20 15:46:48 +01:00
nmlgc 1d5db7155a [Separate translation units] [th02/th03/th05] game_init_op()
Completes P0133, funded by [Anonymous].
2021-01-31 16:53:59 +01:00
nmlgc e8588b1b0a [Separate translation units] [th02] game_exit()
Part of P0133, funded by [Anonymous].
2021-01-31 16:53:55 +01:00
nmlgc 84d4914a3b [Separate translation units] [th02] snd_mmd_resident() (undecompilable)
Reason: Wants to be word-aligned, and the previous version in OP.EXE,
game_exit(), is not, despite having an even length :(
Oh well, at least I'm confident enough about it by now to document it.
And out of all decompilations to be thrown away, this is a pretty
dispensable one.

Part of P0133, funded by [Anonymous].
2021-01-31 15:21:11 +01:00
nmlgc cdbd621f91 [Separate translation units] [th02] snd_determine_mode()
Perfectly decompilable with pseudo-registers. Why did I decide against
them in 2015?

Part of P0133, funded by [Anonymous].
2021-01-31 15:18:09 +01:00
nmlgc 5bbc08c3ef [Separate translation units] [th02] snd_pmd_resident()
Seemingly impossible to decompile further.

Part of P0133, funded by [Anonymous].
2021-01-31 15:18:06 +01:00
nmlgc c77a5fd8ed [Separate translation units] [th02] snd_delay_until_volume()
Part of P0133, funded by [Anonymous].
2021-01-31 15:14:55 +01:00
nmlgc d8bf578ad1 [Separate translation units] [th02] snd_load()
Almost not decompilable for alignment reasons!

Part of P0133, funded by [Anonymous].
2021-01-30 19:57:28 +01:00
nmlgc 3428739f80 [Separate translation units] [th02] .MPTN: Inner load functions
Part of P0133, funded by [Anonymous].
2021-01-30 19:53:00 +01:00
nmlgc ce25a6e579 [Separate translation units] [th02/th03/th05] game_init_main()
Oh look, new content! Gotta finish this push at some point, after all…

Part of P0133, funded by [Anonymous].
2021-01-30 19:50:32 +01:00
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