Commit Graph

56 Commits

Author SHA1 Message Date
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 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 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 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 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 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 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
nmlgc b487e297c4 [Decompilation] [th04/th05] GRCG mode/color setting functions in segment #3
What a beautiful micro-optimization! What's less beautiful though is
the fact that the segment-3 version is only used by a single function,
where it could have easily been inlined.

Part of P0192, funded by [Anonymous], nrook, and -Tom-.
2022-05-01 00:22:03 +02:00
nmlgc fb924f7f9a [Decompilation] [th04/th05] Bosses: Backdrop rendering
Part of P0192, funded by [Anonymous], nrook, and -Tom-.
2022-05-01 00:22:03 +02:00
nmlgc bcf19490f0 [Decompilation] [th05] Stage 1 midboss: Main function
Part of P0192, funded by [Anonymous], nrook, and -Tom-.
2022-05-01 00:22:03 +02:00
nmlgc 71cb7b5e93 [Decompilation] [th05] Shinki: Main function
3rd PC-98 Touhou boss completely decompiled, 28 to go… and the code
quality is taking a nosedive again, especially with that unnecessary
"relative phase" variable that collides with the laser activation flag
in the Devil pattern.
(The nearfunc_t_near workarounds are our fault, though!)

Completes P0191, funded by nrook.
2022-05-01 00:22:03 +02:00
nmlgc 1898ee4564 [Reverse-engineering] [th04/th05] Bosses: Patterns seen / defeat bonus flag
There's the meaning I was looking for in 6ff427a! Far from everything
that's done with this "mode change" variable though – and as we've seen
in 426a531, it's mostly a waste of time to immediately RE all meanings
of this variable across all bosses. So, let's keep using the raw
"phase_state" variable in ASM land.

Part of P0191, funded by nrook.
2022-05-01 00:22:03 +02:00
nmlgc da1558d9ff [Maintenance] [th04/th05] Bosses: Merge BSS definitions into a single file
Part of P0190, funded by nrook.
2022-04-30 14:37:40 +02:00
nmlgc b8907097fa [Reverse-engineering] [th05] Bosses: 16 shared state bytes
Oh *come on*. TH05 not only reuses this bad idea from TH04, it also
uses them 4× as often as TH04, even for midbosses. Unfortunately, even
the first two bytes that are only (properly) used for a single thing in
the Yumeko fight make more sense as part of this array – then, it's a
consistent 16 bytes for both games. The fact that I didn't look further
in b02147b probably also contributed to me missing them in 426a531 last
month.
But yeah, no sense in researching the TH05 ones deeper this time.
b4876b6 has already proven that to be a waste of time.

Part of P0190, funded by nrook.
2022-04-30 14:37:35 +02:00
nmlgc 270d376089 [Maintenance] Add min/max abstractions for constrained random numbers
Way easier to read compared to the mental gymnastics of the original
"offset + range" form, especially since we can also abstract away
subpixels with another layer of wrapper functions. Also brings a bunch
of new speed/angle symmetries to light.

Part of P0190, funded by nrook.
2022-04-30 14:37:23 +02:00
nmlgc c90c7d52c4 [Decompilation] [th04] Stage 4 Marisa: Point-reflected movement
This is the function that causes Marisa's `Divide Error` crash when
called during a 4-frame window during the end of certain patterns.
Just like with Kurumi's division by zero, it's just as undefined here
what should happen instead, and any possible fix can only ever be a
fan-fiction interpretation of the code. And since the community will
have an easier time understanding and debating a C++-level hack instead
of an ASM-level one, it makes sense to first decompile this function…

…and document it, which is actually much harder!

Part of P0189, funded by Arandui and Lmocinemod.
2022-04-17 00:00:35 +02:00
nmlgc 0d703fb2e1 [Decompilation] [th05] Sara: Background rendering
Using the .BB entrance animation as a transition between stage tiles
and the backdrop image. Also implemented in a much better way.

Part of P0189, funded by Arandui and Lmocinemod.
2022-04-16 23:53:47 +02:00
nmlgc 5655b53f10 [Decompilation] [th05] Louise / Alice / Mai & Yuki / Yumeko: Background rendering
It's basically the same function copy-pasted 4 times, differing only in
the backdrop image coordinates and some other inconsequential details.

Part of P0189, funded by Arandui and Lmocinemod.
2022-04-16 23:53:47 +02:00
nmlgc 992cd74970 [Naming] [th04/th05] Bosses: HP fill and .BB tile animation phase constants
These phases are the same across all bosses.

Part of P0189, funded by Arandui and Lmocinemod.
2022-04-16 23:53:47 +02:00
nmlgc 5dca74a77c [Naming] [th04/th05] Boss-specific names for backdrop colorfill functions
Once we decompile whatever can be decompiled of those, we're going to
use the same coordinate constants for both these and the backdrop
image. Ideally, we can even macro (or inline-function) away the entire
implementation, so that the redundancy between TH04's and TH05's Stage
4 bosses won't matter as much.

Part of P0189, funded by Arandui and Lmocinemod.
2022-04-16 23:53:46 +02:00
nmlgc 019405a241 [Maintenance] [th04/th05] Declare common (mid-)boss phases as proper constants
The fanciness of expressing these as signed constants probably hurted
the understandability of the code more than it helped.

Part of P0189, funded by Arandui and Lmocinemod.
2022-04-16 23:53:46 +02:00
nmlgc facc3dbdc9 [Maintenance] [th04/th05] Define grcg_setmode_tdw() with the correct name
Part of P0189, funded by Arandui and Lmocinemod.
2022-04-16 23:53:46 +02:00
nmlgc 6db32b92fe [Maintenance] [th04/th05] Remove `extern "C"` from boss functions
Part of P0189, funded by Arandui and Lmocinemod.
2022-04-16 23:53:46 +02:00
nmlgc ac7822ec71 [Decompilation] [th04/th05] Boss and midboss player shot collision handling
Awesome! The last of the shared TH04/TH05 boss functions, completed
just as the money for that sort of thing ran out. Time to decompile
some actual bosses!

Part of P0188, funded by [Anonymous] and nrook.
2022-03-27 01:50:07 +01:00
nmlgc 38eb77c828 [Decompilation] [th04/th05] Bosses: Item drops
Part of P0188, funded by [Anonymous] and nrook.
2022-03-27 01:35:40 +01:00
nmlgc ac497e8bc4 [Decompilation] [th04/th05] Bosses: Phase switching
Part of P0188, funded by [Anonymous] and nrook.
2022-03-27 01:35:40 +01:00
nmlgc 354a4724f3 [Decompilation] [th04/th05] Bosses: Defeat sequence
With TH04's version hardcoding not only Gengetsu's dialog and
initialization, but also the Bad Ending after having clearing Stage 5
with continues or on Easy difficulty.

Part of P0188, funded by [Anonymous] and nrook.
2022-03-27 01:35:37 +01:00
nmlgc 426a531882 [Reverse-engineering] [th04] Bosses: 16 shared state bytes
With a different meaning (and sometimes, even type) every time they are
used, forcing me to look at details of boss fights way before I wanted…
wonderful. Not sure yet whether they're involved in Kurumi's and
Marisa's division-by-0 crashes, but that kind of wildly shared state is
exactly what causes bugs like these to happen. I did manage to
reproduce the Marisa crash during this research!

Temporarily breaking the rule of immediately reflecting ASM land
declarations in C land, because it makes more sense to render these as
macros, local to their respective pattern functions, and it's way too
early for declaring these. Or late, given that I've now got to add a
third push to this stretch…

Completes P0187, funded by [Anonymous] and Blue Bolt.
2022-03-27 00:48:12 +01:00
nmlgc a03e8a78b8 [Reverse-engineering] [th04] Stage 4 Reimu: Data segment variables
Part of P0187, funded by [Anonymous] and Blue Bolt.
2022-03-27 00:48:06 +01:00
nmlgc 5e4f1f0f1d [Reverse-engineering] [th04] Gengetsu: Wave teleport amplitude
Given how close the string literals of TH04's boss defeat sequence
function are to the end of its data segment, it makes sense to figure
out the three values after it right now.

Part of P0187, funded by [Anonymous] and Blue Bolt.
2022-03-27 00:43:03 +01:00
nmlgc 295d5a8c6c [Decompilation] [th05] Bosses: Player sprite collision
TH05 only…? Yes, moving over a boss sprite doesn't actually kill the
player in TH04.

Part of P0186, funded by [Anonymous] and Blue Bolt.
2022-03-27 00:39:03 +01:00
nmlgc e9b2a98363 [Decompilation] [th04/th05] Bosses / Midbosses: End-of-phase score bonus
Part of P0186, funded by [Anonymous] and Blue Bolt.
2022-03-27 00:33:51 +01:00
nmlgc 66bcd56272 [Naming] [th04/th05] Bosses: Rename `*_phase_end` to `*_phase_next`
Another slightly imprecise uth05win naming convention we can improve
on.

Part of P0186, funded by [Anonymous] and Blue Bolt.
2022-03-26 20:44:54 +01:00
nmlgc 718590908f [Maintenance] [th04/th05] Remove `extern "C"` from more areas of code
Mostly centered around the HUD, popup, overlay, boss, and player shot
functions we're about to reference in the upcoming decompilations.

Part of P0186, funded by [Anonymous] and Blue Bolt.
2022-03-26 20:44:54 +01:00
nmlgc 6400e6a689 [Maintenance] [th04/th05] Boss explosions: Update to current coding standards
Part of P0186, funded by [Anonymous] and Blue Bolt.
2022-03-26 20:44:54 +01:00
nmlgc a21ab3d225 [Decompilation] [th04/th05] Midbosses: Defeat animation update function
This code structure is driving me insane.

Completes P0185, funded by [Anonymous], -Tom-, and Blue Bolt.
2022-03-05 17:50:33 +01:00
nmlgc db05bffca3 [Maintenance] Turn motion_t into a template
motion_t is also used for certain animations in MAINE.EXE, so not all
instances refer to entities in playfield space. Explicitly specifying
the latter now allows us to gain…

Part of P0149, funded by Blue Bolt, Ember2528, and -Tom-.
2021-07-31 09:33:50 +02:00
nmlgc c940059037 [Decompilation] [th05] Shinki + EX-Alice: Background rendering
Palette hacks not included yet. Yup, that's how all phases can use
hardware color #0 as their background color.

Completes P0147, funded by -Tom- and Ember2528.
2021-06-21 15:48:42 +02:00
nmlgc a157739665 [Reverse-engineering] [th04/th05] .CDG slot IDs for MAIN.EXE
64 slots reserved, 16 slots actually used, another 768 bytes of
conventional RAM wasted…

(And yes, that naming convention is indeed meant as a shoutout to all
the RPG Maker veterans out there.)

Part of P0147, funded by -Tom- and Ember2528.
2021-06-21 15:48:41 +02:00
nmlgc b265134541 [Reverse-engineering] [th04/th05] Background rendering function pointers
That could have easily been architected without forcing every boss to
manually set the "background to be drawn while bombing" function
pointer.
And without the laziness of just redrawing all tiles during the blocky
opening animation of certain bombs…

Part of P0147, funded by -Tom- and Ember2528.
2021-06-21 15:48:38 +02:00
nmlgc 8691b23716 [Reverse-engineering] [th04/th05] .BB tile animation: Cel rendering
Not exclusively used for the boss entrance animations, even though its
data is declared in that general vicinity. It's also used for all bombs
in TH04, and Reimu's and Yuuka's bomb in TH05.

Part of P0147, funded by -Tom- and Ember2528.
2021-06-21 15:48:28 +02:00
nmlgc 5990ccd3b9 [Maintenance] Declare CDG blitting functions in C land
Part of P0119, funded by [Anonymous] and -Tom-.
2020-09-21 15:00:01 +02:00
nmlgc fb67d4d054 [Maintenance] Rename all old *_X and *_Y constants to *_LEFT and *_TOP
Part of P0112, funded by [Anonymous] and Blue Bolt.
2020-08-28 15:14:22 +02:00
nmlgc d6f634631f [Maintenance] Declare distinct types for pixel and VRAM sizes
Oh wait, we also need one of those for an upcoming structure!

Part of P0111, funded by [Anonymous] and Blue Bolt.
2020-08-28 14:53:33 +02:00
nmlgc 368f151759 [Maintenance] Declare distinct types for screen, VRAM, and TRAM coordinates
Whew, time to look at every `int` variable we ever declared! The best
moment to do this would have been a year ago, but well, better late
than never. No need to communicate that in comments anymore.

These shouldn't be used for widths, heights, or sprite-space
coordinates. Maybe we'll cover that another time, this commit is
already large enough.

Part of P0111, funded by [Anonymous] and Blue Bolt.
2020-08-28 14:53:30 +02:00
nmlgc 18a8eccd2f [Decompilation] [th05] Bosses: Smooth random movement
Part of P0109, funded by [Anonymous] and Blue Bolt.
2020-08-16 21:41:34 +02:00
nmlgc 023417a1b4 [Maintenance] Move boss declarations to boss.hpp
Part of P0109, funded by [Anonymous] and Blue Bolt.
2020-08-16 21:40:35 +02:00
nmlgc e1f3af547f [Maintenance] [th04/th05] Declare null callbacks in a single place in C land
Part of P0089, funded by [Anonymous] and Blue Bolt.
2020-05-04 16:14:18 +02:00