Commit Graph

97 Commits

Author SHA1 Message Date
nmlgc f5da2a50a5 [Maintenance] [th02/th04/th05] Stage tiles: Move metrics to a separate header
The vertical shmup counterpart to 841d8be. Cleans up the subsystem
hierarchy by ensuring that at least all tile /formats/ code does not
depend on /main/ code.

Part of P0258, funded by [Anonymous] and Blue Bolt.
2023-10-31 22:33:10 +01:00
nmlgc 540174828b [Maintenance] [th05] Bullets: Explicitly use the blue and red ball patnums
PAT_BULLET16_N_BLUE and PAT_BULLET16_N_RED are just meant to be generic
color range indicators with no semantic meaning.

Part of P0245, funded by [Anonymous], Blue Bolt, Ember2528, and Yanga.
2023-06-30 19:59:11 +02:00
nmlgc 51b2df231a [Maintenance] Remove `extern "C"` from vector header inclusions
Part of P0244, funded by Blue Bolt and [Anonymous].
2023-06-10 18:32:25 +02:00
nmlgc 000bac9190 [Maintenance] Random number ring buffer: Fix inconsistencies between & and %
Bracketing is hard!

Part of P0242, funded by Yanga.
2023-06-06 21:11:58 +02:00
nmlgc 2c52cc83b1 [Maintenance] Random number ring buffer: Remove `extern "C"`
Didn't expect to cover it this soon, but I'd really like to have a "is
range a power of two" template.

Part of P0242, funded by Yanga.
2023-06-06 21:07:08 +02:00
nmlgc 1f962c865e [Maintenance] Introduce a generic entity flag enum
Part of P0236, funded by Yanga.
2023-03-29 12:36:55 +02:00
nmlgc b9402be979 [Maintenance] Simplify two-state entity flags
Changing the type to `bool` highlights that these have only two states.
No `switch` required.

Part of P0236, funded by Yanga.
2023-03-29 12:36:55 +02:00
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 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 271554aad9 [Decompilation] [th05] Sara: Pattern 7/9 + 8/9
The one where Sara alternates between firing a slow and a fast spiral
of blue ball ring groups that turns clockwise (7) or counter-clockwise
(8), with each new bullet accelerating by 0.25 pixels per frame.

Part of P0227, funded by nrook.
2023-01-17 10:52:29 +01:00
nmlgc 7aeb5dddd5 [Decompilation] [th05] Sara: Pattern 6/9
The one where Sara fires random rings of red ball bullets every 16
frames.

Part of P0227, funded by nrook.
2023-01-17 10:51:29 +01:00
nmlgc 662685a5d0 [Decompilation] [th05] Sara: Pattern 5/9
The one where Sara fires small arcs of pellets at random angles that
are first limited downwards and then gradually expand at both sides,
with slightly faster blue balls on top.

Part of P0227, funded by nrook.
2023-01-17 10:50:50 +01:00
nmlgc b638e2d965 [Decompilation] [th01] Sara: Phase 3 (with externally selected pattern)
Part of P0227, funded by nrook.
2023-01-17 10:50:39 +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 b535f33461 [Decompilation] [th05] Sara: Pattern 1/9 + 2/9
The ones where Sara fires a counter-clockwise (1) or clockwise (2)
curve of blue ball bullets, with one new group every two frames.

Part of P0227, funded by nrook.
2023-01-17 10:44:58 +01:00
nmlgc 6dd29fe5ba [Decompilation] [th05] Sara: Phase 2 (with externally selected pattern)
Part of P0227, funded by nrook.
2023-01-17 10:44:31 +01:00
nmlgc bcc2669afe [Reverse-engineering] [th05] Sara: State
Going for a union this time, as all but one of the used state bytes
have different semantics in phases 2, 3, and 4.

Part of P0227, funded by nrook.
2023-01-17 10:37:49 +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 f070ee2858 [Naming] [th05] Bosses: Phase functions with externally selected patterns
As soon as we get to Sara, these will do more than just show the gather
animation. If we could change the code, we'd include the pattern
selection in the same function, but the second-best refactor would pass
the pattern function as a parameter, and therefore arrive at this
naming scheme as well.
The function pointer names are fine the way they are – since a boss can
have multiple of these externally selected patterns in more than one
phase and select them based on different rules, it makes little sense
to streamline their names.

Part of P0227, funded by nrook.
2023-01-16 10:39:02 +01:00
nmlgc eb8a4506dc [Naming] Change the _HP suffix to a prefix
Auto-completes much better.

Part of P0227, funded by nrook.
2023-01-16 10:20:28 +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 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 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 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 cfea4971ee [Maintenance] [th01] Publicly define clock direction constants
Part of P0207, funded by GhostPhanom.
2022-08-08 20:11:11 +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 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 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 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 2fa7cc1a4f [Decompilation] [th05] Shinki: Floating movement
As seen during her winged phases.

Part of P0191, funded by nrook.
2022-05-01 00:22:03 +02:00
nmlgc 7fc3208822 [Decompilation] [th05] Shinki: Pattern 11/11
The one where Shinki first fires two point-symmetric 32×32 bullets, and
later adds two alternating spirals of red vector bullets and pellets,
respectively. Final pattern of the boss fight.

Part of P0191, funded by nrook.
2022-05-01 00:22:03 +02:00
nmlgc 293e16a052 [Decompilation] [th05] Shinki: Pattern 10/11
There one where… nah, you all know The Devil Pattern™.

Completes P0190, funded by nrook.
2022-05-01 00:22:03 +02:00
nmlgc 2027639c81 [Decompilation] [th05] Shinki: Pattern 9/11
The one where Shinki fires aimed purple 32×32 ball bullets, together
with symmetric rotating spreads from the left and right edges of her
wings whose angles rotate along ¾ of a circle.

Part of P0190, funded by nrook.
2022-05-01 00:22:03 +02:00
nmlgc 8b79dd5371 [Decompilation] [th05] Shinki: Pattern 8/11
The one where Shinki's white wings turn purple, and fire 16 purple
32×32 bullets after the color change.

For some reason, OMAKE.TXT says that these wings are black?!?

Part of P0190, funded by nrook.
2022-05-01 00:22:03 +02:00
nmlgc 55cd74326c [Decompilation] [th05] Shinki: Pattern 7/11
The one where Shinki walls off both the left and right edges of the
playfield with triangular walls out of spread bullets, and fires
cheetos inside the corridor.

Part of P0190, funded by nrook.
2022-05-01 00:22:03 +02:00
nmlgc 4ea60d1155 [Decompilation] [th05] Shinki: Pattern 6/11
The one where random blue 32×32 bullets rain from near the top of the
playfield, together with aimed spreads from random positions on
Shinki's wings. First white-wing pattern.

Part of P0190, funded by nrook.
2022-05-01 00:22:02 +02:00
nmlgc 3b21a75cab [Decompilation] [th05] Shinki: Pattern 5/11
The one where Shinki spawns her wings, which fire 50 quick random
bullets as soon as they appear. Featuring the first reliance on a piece
of state set by an earlier boss, which technically affects gameplay!

Part of P0190, funded by nrook.
2022-05-01 00:22:02 +02:00
nmlgc d3819445ba [Decompilation] [th05] Shinki: Pattern 4/11
The one where Shinki fires dense, aimed stacks of blue bullets in quick
succession, while flying to a random point.

I really, *really* don't want to believe that ZUN manually wrote these
micro-optimized setter functions that abuse the bullet template
structure layout, but I don't really have any other idea how to get
those out of the compiler…

Part of P0190, funded by nrook.
2022-05-01 00:22:02 +02:00
nmlgc 390976c24d [Decompilation] [th05] Shinki: Pattern 3/11
The one where Shinki fires random blue directional and kunai bullets
from her left and right side, while flying to a random point.

Part of P0190, funded by nrook.
2022-05-01 00:22:02 +02:00
nmlgc 4bd8e01c3d [Decompilation] [th05] Shinki: Gather circle intro for patterns in phases 2/3
Featuring something that looks like part of an unused pattern, but was
actually just copy-pasted from Yumeko. Some evidence for Shinki having
been coded after Yumeko, at least.

Part of P0190, funded by nrook.
2022-05-01 00:22:02 +02:00
nmlgc 3fc58928ec [Decompilation] [th05] Shinki: Pattern 2/11
The one where Shinki fires two simultaneous rings of blue bullets, with
the second one moving twice as fast.

Part of P0190, funded by nrook.
2022-04-30 17:44:15 +02:00