Commit Graph

532 Commits

Author SHA1 Message Date
nmlgc cc42f949e1 [Maintenance] Remove the vsync_reset_*() macros
They obscure the simple nature of these VSync counters more than they
help.

Part of P0229, funded by Ember2528.
2023-02-28 08:07:52 +01:00
nmlgc ee58546025 [Decompilation] [th05] Lasers: 2D vector construction
More custom code generation!

Part of P0228, funded by [Anonymous] and nrook.
2023-01-17 11:46:25 +01:00
nmlgc a31c5a4a4f [Decompilation] [th04] Player: Input → movement velocity
That's not nice to the call site!

Part of P0228, funded by [Anonymous] and nrook.
2023-01-17 11:44:15 +01:00
nmlgc bfd24c6ae3 [Decompilation] Turn the FS/GS prefix workaround into a full-on code generator
If we double down on this concept by defining all needed prefix and R/M
opcodes, the code turns out much simpler if we __emit__() even the
basic, non-broken case. And if the inlined functions directly take
the opcode bytes as parameters, we don't even need templates.

Completes P0227, funded by nrook.
2023-01-17 11:40:36 +01:00
nmlgc ed444c6b1c [Decompilation] [th05] Sara: Main function
9th PC-98 Touhou boss almost completely decompiled, 22 to go!
I definitely did not miss the convoluted control flow of the TH05 ones.

Part of P0227, funded by nrook.
2023-01-17 11:32:34 +01:00
nmlgc 89aeb600af [Decompilation] [th05] Sara: Pattern 9/9
The one where Sara spawns a symmetric laser pair to wall the player
into a 0x14° corridor while firing dense spread pellets and random blue
balls every 16 seconds.

Part of P0227, funded by nrook.
2023-01-17 10:53:31 +01:00
nmlgc 9a8f15a2ab [Decompilation] [th05] Sara: Pattern 4/9
The one where Sara fires stacks of red ball bullets every 8 frames.

Part of P0227, funded by nrook.
2023-01-17 10:47:43 +01:00
nmlgc 478f8f262d [Decompilation] [th05] Sara: Pattern 3/9
The one where Sara fires a single aimed spread stack of red ball
bullets.

Part of P0227, funded by nrook.
2023-01-17 10:45:54 +01:00
nmlgc 539b3ec20b [Maintenance] [th05] Bullets: Split off low-level stack/spread set optimization
Easier to get the bit shifts right if you focus on them in a separate
helper function that is decoupled from any semantics – and Sara is
about to add two more variants of these setters. By interleaving the
per-difficulty count/delta values instead of listing them separately,
it also turns out that I originally mixed them up in Shinki's 4th
pattern. Reads much better now.

Part of P0227, funded by nrook.
2023-01-17 10:34:15 +01:00
nmlgc 990588a4ea [Research] Finally figure out relativity of near references
Biggest decompilation breakthrough of the year already? Completely
removes the need for the "set near pointer to far function" hack, and
solves quite a few upcoming issues.
The TASM manuals did have a few pages on the topic of segments and
groups, but there's absolutely nothing about it in the TCC ones beyond
the three-sentence description of `#pragma codeseg` and that completely
unhelpful "🤷" of an explanation for the `Fixup overflow` error…

Part of P0227, funded by nrook.
2023-01-16 12:05:29 +01:00
nmlgc d9427b0761 [Maintenance] [th02/th04/th05] Remove `extern "C"` from more areas of code
The TH04/TH05 gather functions, as well as the TH02 vector functions.

Part of P0227, funded by nrook.
2023-01-16 10:16:12 +01:00
nmlgc 4f853261fa [Decompilation] [th05] Stage 5 midboss: Rendering
15 lines of code, and still not quirk-free.

Completes P0225, funded by Enderwolf, Blue Bolt, 32th System, and Yanga.
2022-11-30 22:46:22 +01:00
nmlgc 4e648a66be [Naming] [th04/th05] Midbosses: Defeat animation rendering
Part of P0225, funded by Enderwolf, Blue Bolt, 32th System, and Yanga.
2022-11-30 22:46:22 +01:00
nmlgc 944a66cf77 [Maintenance] [th04/th05] Bosses: Single-file, multi-segment code structure
As implied in adffa1c, a single segment-switching translation unit for
both rendering functions and game logic is the most straightforward
solution for those two games. Especially once you look at TH04, and
realize that the wildly chaotic order of the *_fg_render() functions in
the first code segment exactly matches the order of the *_update()
functions in the third.

Part of P0225, funded by Enderwolf, Blue Bolt, 32th System, and Yanga.
2022-11-30 22:46:22 +01:00
nmlgc 68aa320982 [Decompilation] [th02/th04/th05] Text overlay: Fill functions
Part of P0225, funded by Enderwolf, Blue Bolt, 32th System, and Yanga.
2022-11-30 22:46:22 +01:00
nmlgc 6a29e43b43 [Reverse-engineering] graph_putsa_fx(): Weight function cutoffs and glitches
It's easy to blame ASM micro-optimizations for bugs like these, but the
original C++ version from TH01 was equally bugged for FX_WEIGHT_BLACK.

Part of P0225, funded by Enderwolf, Blue Bolt, 32th System, and Yanga.
2022-11-30 22:46:22 +01:00
nmlgc 6d977a9df7 [Decompilation] [th03/th04/th05] Cutscenes: Main script parsing loop
Part of P0225, funded by Enderwolf, Blue Bolt, 32th System, and Yanga.
2022-11-30 22:46:22 +01:00
nmlgc 8118e61c77 [Decompilation] [th03/th04/th05] Cutscenes: Script opcode interpreter
Even that part's the same in these three games… except for the 27 small
places where it isn't, 7 of which are purely coding style cosmetics.

Completes P0224, funded by Splashman and -Tom-.
2022-11-30 22:46:22 +01:00
nmlgc f01e46700d [Maintenance] [th04/th05] Cutscenes: Move box code to the main translation unit
With the script parsing and picture/box rendering functions being as
interleaved as they are, it makes little sense to keep the cutscene
code in more than one translation unit. How would those translation
units even be called? This time, having everything in one file should
beat the few hundred preprocessor-removed lines of code that we end up
adding to each one of the three affected games – and ultimately, you'd
want to merge those systems into one translation unit anyway.

Part of P0224, funded by Splashman and -Tom-.
2022-11-30 19:31:14 +01:00
nmlgc 6f8b32ca4a [Decompilation] [th03/th04/th05] Cutscenes: Masked blitting of new pictures
Part of P0223, funded by Blue Bolt and rosenrose.
2022-11-30 19:16:35 +01:00
nmlgc fb9f18e967 [Decompilation] [th03/th04/th05] Cutscenes: EGC initialization
That only leaves the TH02 versions of this function that really should
have been defined at one central location.

Part of P0223, funded by Blue Bolt and rosenrose.
2022-11-30 19:08:52 +01:00
nmlgc 023cdacc36 [Decompilation] [th03/th04/th05] Cutscenes: Script loading and freeing
Part of P0223, funded by Blue Bolt and rosenrose.
2022-11-30 19:08:28 +01:00
nmlgc 576f49129a [Decompilation] [th05] Cutscenes: Return key wait animation
Needlessly blitting glyphs to VRAM until the very end, eh?

Part of P0223, funded by Blue Bolt and rosenrose.
2022-11-30 19:08:05 +01:00
nmlgc 815bcc8308 [Decompilation] [th03/th04/th05] Cutscenes: Input handling
Here's an entire commit to point out why the difference between these
function names matters and shouldn't be #define'd away in some central
input header file.

Part of P0223, funded by Blue Bolt and rosenrose.
2022-11-30 19:08:02 +01:00
nmlgc 7cda9e28b2 [Decompilation] [th04/th05] Cutscenes: Text blending animation
Part of P0223, funded by Blue Bolt and rosenrose.
2022-11-30 17:11:00 +01:00
nmlgc ee717c1d19 [Reverse-engineering] [th03/th04/th05] Cutscenes: State variables
You can fast-forward through cutscenes by holding Escape in these
games?! And the script interpreter adds automatic line breaks?!

Part of P0223, funded by Blue Bolt and rosenrose.
2022-11-30 17:10:19 +01:00
nmlgc ccd5b70b9f [Maintenance] [th03/th04/th05] Cutscenes: Move into a separate subdirectory
Thanks to TH03 having text-below-picture cutscenes before stages 8 and
9, the `/end/` directory is the wrong place to keep this code. And as
we're soon going to see, this feature did evolve during these three
games.

Part of P0223, funded by Blue Bolt and rosenrose.
2022-11-30 17:02:34 +01:00
nmlgc 2458172c98 [Maintenance] [th02/th03/th04/th05] Define a constant for a white VRAM color
Part of P0223, funded by Blue Bolt and rosenrose.
2022-11-30 17:00:42 +01:00
nmlgc 55d98369d9 [Maintenance] master.hpp: Pass element counts to the hmem_allocbyte() wrapper
Which gets rid of the declaration for `size_t` in a grand total of two
translation units.

Part of P0223, funded by Blue Bolt and rosenrose.
2022-11-30 16:59:09 +01:00
nmlgc 753f73f5f2 [Maintenance] master.hpp: Centrally define packfile filename length
The later games need this constant for their buffers as well, and it's
not just needed for loading sound files. Might be overkill to force all
of `master.hpp` to be #included in some additional places, but the
alternative would have been to move it to a `fn_len.hpp` file.
Ultimately, this constant *is* related to master.lib.

Part of P0223, funded by Blue Bolt and rosenrose.
2022-11-30 16:58:30 +01:00
nmlgc e83d0772b2 [Maintenance] Turn TRAM width types into Shift-JIS width types
These are more generally useful for general text width calculations
that don't necessarily involve TRAM.

Part of P0223, funded by Blue Bolt and rosenrose.
2022-11-30 16:46:35 +01:00
nmlgc 47cd413064 [Maintenance] Reclassify previously labeled ZUN bugs as quirks where applicable
Part of P0216, funded by JonathKane.
2022-08-16 01:44:16 +02:00
nmlgc 650c1e3364 [Maintenance] Review any redundancies and label them as ZUN bloat
Or quirk, in the case of the slow TH01 ending picture blitting.

Part of P0216, funded by JonathKane.
2022-08-16 01:43:14 +02:00
nmlgc 690b4df14b [Maintenance] Fix another bunch of accumulated typos and dead code
Part of P0216, funded by JonathKane.
2022-08-16 01:38:12 +02:00
nmlgc 363fd54e6a [Decompilation] [th01] Stage bonus: Main function
Completes P0212, funded by GhostRiderCog, Lmocinemod, and LeyDud.
2022-08-11 23:18:29 +02:00
nmlgc 79e9ab77dc [Maintenance] Simplify EGC macros and hardcode the chip's register size
No reason to continue pretending it supports anything else.

Part of P0212, funded by GhostRiderCog, Lmocinemod, and LeyDud.
2022-08-11 18:03:44 +02:00
nmlgc 60a7e44b53 [Maintenance] Introduce proper Shift-JIS and JIS X 0208 types
Much more semantic than that twobyte_t abomination.

Part of P0212, funded by GhostRiderCog, Lmocinemod, and LeyDud.
2022-08-11 15:53:13 +02:00
nmlgc a10fe95b31 [Maintenance] Fix comment↔code associations
• Comments that describe all lines of code until a blank one are placed
  into the lines immediately above
• Comments that describe an entire demarcated block are placed
  immediately below the dash row at the top
• In any case, there should be a blank line after the top comment of
  a demarcated block, to keep IntelliSense-style systems from applying
  the block comment to the first actual line of code…
• …but there shouldn't be one before the dash row at the bottom, where
  it'd be redundant.

Part of P0207, funded by GhostPhanom.
2022-08-08 20:10:53 +02:00
nmlgc 386d9cd4cb [Contributing] Establish a more greppable convention for space-saving `union`s
How did I end up with x86 registers of all things?

Part of P0207, funded by GhostPhanom.
2022-08-08 20:10:47 +02:00
nmlgc 456768a4ff [Contributing] Define `struct`, `class` and `template` naming conventions
Again, these are what I've been mostly following, apart from a few
inconsistencies which this commit also fixes.

Part of P0207, funded by GhostPhanom.
2022-08-08 20:10:38 +02:00
nmlgc 0c682b5bc0 [Maintenance] Declare the optimization_barrier() a single time
And put that single instance into the compiler optimization workaround
section of `decomp.hpp`.

Part of P0204, funded by [Anonymous].
2022-07-10 13:45:18 +02:00
nmlgc 3e79deeb3a [Contributing] Define function brace placement rules
I've been following them pretty consistently for a while now, time to
finally write them down.

Part of P0204, funded by [Anonymous] and Yanga.
2022-07-10 13:45:18 +02:00
nmlgc 901eda4594 [Maintenance] Consistently indent preprocessor macros
Let's see if anyone ever tries to compile this codebase with a pre-C89
compiler that enforces the # at the beginning of the line.

Part of P0203, funded by [Anonymous] and GhostRiderCog.
2022-07-10 13:06:26 +02:00
nmlgc bca1b7d38a [Maintenance] Add a `nullptr` polyfill to platform.h
Which allows us to remove <stddef.h> from translation units that just
needed it for `NULL`.

Part of P0203, funded by [Anonymous] and GhostRiderCog.
2022-07-10 13:02:51 +02:00
nmlgc 6f2881f056 [Maintenance] Remove `extern "C"` from more areas of code
The .PTN functions, vector functions, and egc_copy_rect_1_to_0_1()
(finally!) from TH01, as well as playfld.hpp from all games(finally!),
together with a bunch of other functions in their vicinity.

Part of P0201, funded by Ember2528 and Yanga.
2022-06-24 23:28:19 +02:00
nmlgc e1f3f9fe0b [Decompilation] [th04/th05] Demo Play: Reading the replay file
Yeah, nothing you'd want to use even as the base for a community-usable
replay format.

Completes P0192, funded by [Anonymous], nrook, and -Tom-.
2022-05-01 00:22:04 +02:00
nmlgc 8e06497d4b [Separate translation units] [th04/th05] vector2_near (undecompilable)
Reason: Too much micro-optimization using 32-bit registers, which
aren't supported by Turbo C++'s inline assembler. It's also just
another variation on a common function we've decompiled time and time
again.

Part of P0192, funded by [Anonymous], nrook, and -Tom-.
2022-05-01 00:22:04 +02:00
nmlgc c41bfbaf3e [Separate translation units] [th04/th05] Spark sprite spawning (undecompilable)
Reason: Saving SI and DI on the stack way too late. Just because ZUN
absolutely *had* to move the clipping condition before these two PUSH
instructions… Was it really necessary to save a total of 4 instructions
for an unlikely worst case in a function that's maybe called like 10-20
times per frame *at worst*?

Part of P0192, funded by [Anonymous], nrook, and -Tom-.
2022-05-01 00:22:04 +02:00
nmlgc 04de2fddd9 [Decompilation] [th05] Bullets: Sprite selection by angle
And we're right back to dumb micro-optimizations.

Part of P0192, funded by [Anonymous], nrook, and -Tom-.
2022-05-01 00:22:04 +02:00
nmlgc 852f2dd176 [Maintenance] [th04/th05] Drop the `_seg1` suffix from the GRCG functions
It's the `_seg3` variants that are the anomaly here.

Part of P0192, funded by [Anonymous], nrook, and -Tom-.
2022-05-01 00:22:03 +02:00