Commit Graph

56 Commits

Author SHA1 Message Date
nmlgc 034a7db98c [Decompilation] [th05] Lasers: Update function
In which the shrink types """conveniently""" use a signed comparison
that effectively limits their width to 127 pixels, which forces a
shrink/nonshrink distinction upon the entire rest of the code. 🙄

Part of P0228, funded by [Anonymous] and nrook.
2023-01-17 12:16:49 +01:00
nmlgc c8997cd500 [Maintenance] [th05] Lasers: Prepare for two segments in one translation unit
Part of P0228, funded by [Anonymous] and nrook.
2023-01-17 12:10:52 +01:00
nmlgc bb42f673e9 [Decompilation] [th05] Lasers: Collision detection
Started out with the usual amount of decompilation workarounds for this
low-level laser code, but ended up requiring one on almost every line
just because ZUN reversed the function prolog… 🙄

Part of P0228, funded by [Anonymous] and nrook.
2023-01-17 11:58:17 +01:00
nmlgc 15a047fc74 [Decompilation] [th05] Lasers: Ray rendering
A year ago, I would have considered this undecompilable. Turns out that
this function really benefitted from a decompilation against all odds,
especially with these 4 different views on the same 8 local variables.

Part of P0228, funded by [Anonymous] and nrook.
2023-01-17 11:53:47 +01:00
nmlgc b989076579 [Decompilation] [th05] Lasers: Line construction
Part of P0228, funded by [Anonymous] and nrook.
2023-01-17 11:47:01 +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 40b66c46eb [Maintenance] [th05] Bullets: Rearrange comments for circular group types
VS Code doesn't seem to properly syntax-highlight C-style comments that
start on a #define line and end in the line below. But even apart from
that, this rearrangement ensures that IntelliSense correctly assigns
both lines to BGCC_SPREAD as I intended it.

Part of P0227, funded by nrook.
2023-01-17 10:35:57 +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 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 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 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 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 8fce97ea1c [Maintenance] Add a static_assert() polyfill to platform.h
Part of P0198, funded by Lmocinemod and Ember2528.
2022-06-16 22:50:31 +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
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 9ef178431a [Maintenance] [th05] Shinki: #include 32×32 ball code from the boss script
We won't get that one padding byte in front of the shinki_update()
switch table otherwise.

Part of P0191, funded by nrook.
2022-05-01 00:22:03 +02:00
nmlgc 37fac9a2a0 [Maintenance] [th05] Custom entities: Introduce separate template structures
Since the game uses global state to define its patterns, we'd really
like to see immediately which of the structure fields are relevant for
spawning bullets. This makes it easier to spot which of the patterns
rely on fields set in previous patterns – and there are several that
do.

Part of P0190, funded by nrook.
2022-05-01 00:22:02 +02:00
nmlgc c963e2a1e4 [Maintenance] [th04/th05] Bullets: Move pellet rendering to its own header
Removes an unneeded transitive dependency on planar.h from all but one
translation unit.

Part of P0190, funded by nrook.
2022-04-30 14:37:46 +02:00
nmlgc 63091686e2 [Maintenance] [th04/th05] Remove `extern "C"` from more areas of code
hud_hp_put(), hud_hp_update_and_render(), player_angle_from(),
select_for_playchar(), and the midboss functions.

Part of P0190, funded by nrook.
2022-04-30 14:37:28 +02:00
nmlgc 306a504ef5 [Naming] [th05] Officially rename "curve bullets" to "cheetos"
Short, sweet, fits more nicely into 8.3 filenames than "curve bullets"
does, and 76.7% of fans agree:

	https://twitter.com/ReC98Project/status/1500256959785746434

OMAKE.TXT calls them "homing lasers", but… eh, nah.

Part of P0190, funded by nrook.
2022-04-29 03:28:44 +02:00
nmlgc e881f95ce1 [Decompilation] [th05] Shinki's 32×32 balls: Update function
Completes P0188, funded by [Anonymous] and nrook.
2022-03-27 01:50:07 +01:00
nmlgc adffa1ccf9 [Decompilation] [th05] Shinki's 32×32 balls: Spawn function
Wait, wouldn't it be cool if we could keep the render, spawn, and
update functions in the same translation unit, by switching code
segments in the middle of the file? Let's hope this works out, and give
the source file an all-encompassing generic name.

Part of P0188, funded by [Anonymous] and nrook.
2022-03-27 01:50:07 +01:00
nmlgc 83ff3c9ec9 [Maintenance] [th04/th05] Bullets: Move clear/zap declarations to new header
Part of P0188, funded by [Anonymous] and nrook.
2022-03-27 01:29:03 +01:00
nmlgc a907feacf8 [Decompilation] [th05] Lasers: Spawn and control functions
Part of P0185, funded by [Anonymous], -Tom-, and Blue Bolt.
2022-03-05 17:50:27 +01:00
nmlgc 360e07a413 [Maintenance] Add a new typedef for unsigned Q4.4 values
Part of P0185, funded by [Anonymous], -Tom-, and Blue Bolt.
2022-03-05 15:31:50 +01:00
nmlgc 3850f8aafb [Maintenance] [th05] Declare laser symbols in C land, using current conventions
Oh hey, these 2018 variable names weren't completely bad!

Part of P0185, funded by [Anonymous], -Tom-, and Blue Bolt.
2022-03-05 15:31:50 +01:00
nmlgc 96ed07f31e [Maintenance] [th05] Move laser-related code to the `main/bullets` subdirectory
Following the choice I made for TH01.

Part of P0185, funded by [Anonymous], -Tom-, and Blue Bolt.
2022-03-05 15:31:50 +01:00
nmlgc c63e05ed2d [Decompilation] [th05] Curved bullets: Spawn function
Part of P0185, funded by [Anonymous], -Tom-, and Blue Bolt.
2022-03-05 15:31:50 +01:00
nmlgc 944654596d [Decompilation] [th05] Curved bullets: Update function
The algorithm for gradually rotating these clockwise or counterclockwise
towards the player could have been 5 lines long. ZUN blows it up to 26
lines.

Also, a 16×16 killbox for the head node, and a 12×12 one for trail
nodes.

Part of P0185, funded by [Anonymous], -Tom-, and Blue Bolt.
2022-03-05 15:31:50 +01:00
nmlgc 07b956b3ad [Maintenance] [th04/th05] Move bullet code into dedicated segments
Too bad that alignment constraints do in fact force us to compile
th04/bullet_u.cpp and th04/bullet_a.cpp separately. 😕

Part of P0184, funded by -Tom-.
2022-03-05 15:31:50 +01:00
nmlgc 9471e133e9 [Decompilation] [th05] Bullets: Sprite selection for angled bullets
Hopelessly hardcoded.

Part of P0184, funded by -Tom-.
2022-03-05 15:31:50 +01:00
nmlgc 5fac2006ff [Maintenance] Consistently use "score" instead of "points"
Or at least in addition.

Part of P0172, funded by [Anonymous] and Blue Bolt.
2021-12-27 00:50:39 +01:00
nmlgc 101684c235 [Separate translation units] [th05] Rank-based speed tuning
Also not worth decompiling, because:
• It would break return value semantics
• The algorithm is identical to TH04 (except for that one divisor)
• Small function
• Next to a bunch of more critical, undecompiled functions
• Decompilation would be messy anyway

Part of P0152, funded by -Tom- and [Anonymous].
2021-07-31 21:09:37 +02:00
nmlgc 18d4aa43f8 [Reverse-engineering] [th05] Bullets: Spawn wrappers
And that's it! Finally RE'd every bullet spawning function in TH04 and
TH05! 🎉
These really aren't worth adding a translation unit for either, in the
end. Not least because they decide to keep bullet_template.speed from
being mutated via PUSH and POP, which we can only express via inline
assembly in C land.

Part of P0152, funded by -Tom- and [Anonymous].
2021-07-31 21:09:36 +02:00
nmlgc 6127ca0ec1 [Reverse-engineering] [th05] Bullets: Velocity and angle calculation (undecompilable)
Reason: That switch statement. How should we even?

Well, the code *is* fairly good. After looking very deep into it, and
spending 35% of that function on blank lines (for logical grouping) and
explanatory comments, that is…

Part of P0152, funded by -Tom- and [Anonymous].
2021-07-31 21:09:36 +02:00
nmlgc 4d3a1eace8 [Decompilation] [th05] Bullets: Clipping and pre-spawn hit test
Deciding whether to decompile this one or not seemed to be a tough
choice. Should we *really* introduce two more translation units just
for the sake of decompiling another function that's identical to its
TH04 counterpart anyway?
Well, turns out it actually isn't: TH05 does in fact *not* immediately
clip bullets that are spawned on top of the player. Which might sound
like it has a notably different effect on gameplay… except that it
doesn't.
So yeah, good we've decompiled it, and got to show that more clearly.

Part of P0152, funded by -Tom- and [Anonymous].
2021-07-31 21:09:30 +02:00
nmlgc e9788d8519 [Maintenance] [th05] Correctly declare the rank-based speed tuning function
And actually rename to "tune", which is what we use everywhere else.

Part of P0152, funded by -Tom- and [Anonymous].
2021-07-31 20:19:33 +02:00
nmlgc ddc6c1aa3f [Reverse-engineering] [th05] Bullets: Fix wrongly RE'd slowdown logic
Spent 4 pushes on the basic types and constants in 2020, still ended up
up getting this wrong and documenting the opposite of what TH05 actually
does…

Part of P0152, funded by -Tom- and [Anonymous].
2021-07-31 20:19:33 +02: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 b855592c0a [Maintenance] [th04/th05] Bullets: Document the random speed range
Part of P0149, funded by Blue Bolt, Ember2528, and -Tom-.
2021-07-31 09:33:49 +02:00
nmlgc 75c4f2d3cc [Reverse-engineering] [th04/th05] Bullets: Distinguish clear and zap mechanics
And actually document them correctly.

Clear: Custom duration, awards constant points per bullet during the
       entire duration, plays a decay animation
  Zap: Fixed duration, awards a semi-exponential bonus for all bullets
       alive on the first frame, plays a, um, "zapping" animation… in
       TH04, because it's bugged in TH05 :zunpet:

Part of P0149, funded by Blue Bolt, Ember2528, and -Tom-.
2021-07-31 09:33:35 +02:00
nmlgc 751481b658 [Maintenance] Assign segment-specific names to the motion_update() variants
Well, we *could* pointlessly decompile this function into an unreadable
mess, but only if we throw away the semantics of the return value, and
replace its type with `void` or `uint32_t`.
(Turbo C++ can't cast registers to a struct value, and adding a
constructor to SPPoint would break everything else, if it even works.)
ZUN's original usage code doesn't care either way, because it only ever
accesses the returned value directly through DX:AX.

Part of P0148, funded by [Anonymous].
2021-07-21 00:35:02 +02:00
nmlgc 23c46c6654 [Maintenance] [th05] Get rid of th05.hpp
That was surprisingly painless!

Part of P0147, funded by -Tom- and Ember2528.
2021-06-21 15:48:39 +02:00
nmlgc 8a5a9accd6 [Maintenance] Rename pellet/bullet "patterns" to "groups"
We're going to need some name for the longer, boss-specific danmaku
animations. Turns out that these are exactly called "patterns" in
Sparen's glossary:

	https://sparen.github.io/ph3tutorials/ddsg0.html#sub4

So what we called a "pattern" is actually called a "group". Whoops!

Part of P0142, funded by Yanga.
2021-05-27 20:21:09 +02:00
nmlgc 0dcd0b8136 [Maintenance] Reimplement TASM's ARG directive for `MOV BX, SP` functions
`cPtrSize` is simply the wrong constant for calculating parameter
offsets on the stack, because it corresponds to the memory model's
default distance, not the function's distance. Luckily, ARG has a
RETURNS clause, and if you declare all parameters in there, ARG won't
emit that pesky and unnecessary `ENTER 0, 0` instruction. Big discovery
right there!
Sadly, ARG is unusable for ZUN's silly functions that keep the base
pointer in BX. TASM declares the resulting equates as `[BP+offset]`,
and it's apparently impossible to only get `offset` out of such an
equate later.

So, rather than staying with numbers, let's reimplement ARG for these
functions instead. This way, we can even abstract away the stack clear
size for the `RET` instructions.
It's a bit rough around the edges though, forcing you to explicitly
specify the function distance, and to pass the parameters in reverse
order compared to the C declaration (thankfully, all of these use the
PASCAL calling convention). It also doesn't work with more complex
types yet. But certainly better than numbers.

Part of P0134, funded by [Anonymous].
2021-02-20 23:50:00 +01:00
nmlgc ec5b75daab [Maintenance] [th05] Yumeko's blades are actually swords, as stated in OMAKE.TXT
*Technically* also a uth05win inaccuracy. That codebase went with
"KnifeBullet", which seemed right, so I just ran with it without
researching it further… My bad.

(Maintenance mode commit)
2020-09-30 18:12:53 +02:00
nmlgc 6cd11b0a44 [Reverse-engineering] [th05] Bullets: Pellet delay cloud render list
Making sure that we don't ever have to iterate over the 8×8 pellet part
of the bullet array during rendering… sure, but why not give the same
optimization treatment to the 16×16 bullets?

Part of P0112, funded by [Anonymous] and Blue Bolt.
2020-08-28 15:31:02 +02:00