Commit Graph

1709 Commits

Author SHA1 Message Date
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 f3afd37e8f [Reverse-engineering] [th04/th05] .BB tile animation: Filling a single tile
Sure, it's still a micro-optimization, but at least it's __fastcall for
once! And doesn't assume ES to have been set to a VRAM segment. So not
*that* optimized 😛

Part of P0147, funded by -Tom- and Ember2528.
2021-06-20 19:44:40 +02:00
nmlgc ebbb5b8255 [Maintenance] Move tile-related files to their own subdirectory
The next commit will make clear that tile functionality is not a subset
of the non-boss stage code.

Part of P0147, funded by -Tom- and Ember2528.
2021-06-20 19:37:20 +02:00
nmlgc 11b5febc5a [Maintenance] [th04/th05] Move midboss declarations to their own header file
Part of P0147, funded by -Tom- and Ember2528.
2021-06-20 19:36:14 +02:00
nmlgc 456b621c3a [Decompilation] [th05] Shinki: Background types B, C, and D
Thanks, alignment, for forcing all of these into one commit! 🙂

Completes P0146, funded by -Tom- and Ember2528.
2021-06-10 22:52:29 +02:00
nmlgc f5702a599b [Decompilation] [th05] Shinki: Background type B initialization and gravity
We're really going to have a needless "update, part 1" function for all
four background types, eh?

Part of P0146, funded by -Tom- and Ember2528.
2021-06-10 21:43:11 +02:00
nmlgc a9496fa10f [Decompilation] [th05] Shinki: Background type A rendering
The one in the first four phases, with the two parallel zooming lines
that give the impression of flying into a corridor, and random blue
particles shooting out from the center.

Part of P0146, funded by -Tom- and Ember2528.
2021-06-10 21:42:42 +02:00
nmlgc 4672f226bb [Decompilation] [th05] Shinki: Background particle rendering
We really wouldn't have wanted to start writing inline ASM in the
middle of a conditional expression just to get that janky `CMP AX, 0`
instead of TCC's sensible `OR AX, AX` optimization.

Part of P0146, funded by -Tom- and Ember2528.
2021-06-10 09:01:31 +02:00
nmlgc b66400b3d2 [Decompilation] [th05] Shinki: Background type A initialization and rotation
Oh hey, a uth05win naming convention I have no qualms about adopting,
for once!
(Note from the future: It's actually really smart! The animation you
see is dependent on the state from previous background types, so it
makes sense to reduce the names to the original sequence.)

Part of P0146, funded by -Tom- and Ember2528.
2021-06-09 23:13:00 +02:00
nmlgc aae96aec45 [Decompilation] Find out how to bypass TCC's optimization of 0 immediates
By deferring that immediate 0 to link time. 🤦

Part of P0146, funded by -Tom- and Ember2528.
2021-06-09 23:12:04 +02:00
nmlgc 8426f3e13f [Maintenance] Make the playfield fraction functions available to ≥TH02
Part of P0146, funded by -Tom- and Ember2528.
2021-06-09 23:10:01 +02:00
nmlgc 08bc188e7d [Decompilation] [th01] Konngara: Pattern 1/12
The one where Konngara fires 4 diamonds in a cross-shaped motion
towards the edges of the screen, with random pellets raining down for
200 frames afterwards.

Completes P0142, funded by Yanga.
2021-05-27 20:21:21 +02:00
nmlgc 06c4694501 [Decompilation] Add inline functions to calculate playfield fractions
Oh no, another place in which I'm going too far?! Just because I'm sick
of hardcoded number literals after 6 years? Hm…

Part of P0142, funded by Yanga.
2021-05-27 20:21:21 +02:00
nmlgc a2bc97c413 [Naming] [th01] Konngara: Generic pattern state variable
Correctly typed local variables still weren't quite in fashion yet.

Part of P0142, funded by Yanga.
2021-05-27 20:21:20 +02:00
nmlgc 09231dc23f [Decompilation] [th01] Konngara: Sword slash rendering
"Rendering".

Part of P0142, funded by Yanga.
2021-05-27 20:21:20 +02:00
nmlgc 499472e8e4 [Decompilation] [th01] Konngara: Face rendering
And that's everything about it already.

Part of P0142, funded by Yanga.
2021-05-27 20:21:19 +02:00
nmlgc 94c1796869 [Decompilation] [th01] Konngara: Sprite freeing
Part of P0142, funded by Yanga.
2021-05-27 20:21:18 +02:00
nmlgc 4fe93d3699 [Decompilation] [th01] Konngara: Initial variables
Part of P0142, funded by Yanga.
2021-05-27 20:21:17 +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 cb6367a54b [Maintenance] [th01] Fix the type of CPellets::add_single()'s `angle` parameter
Amazing how both an `int` and an `unsigned char` parameter generate the
exact same ASM if they're only passed on to a single function that
widens them to a 16-bit type.

Part of P0142, funded by Yanga.
2021-05-27 19:36:04 +02:00
nmlgc 76a1d8d65e [Reverse-engineering] [th01] Bosses: Current phase
Part of P0142, funded by Yanga.
2021-05-27 19:36:04 +02:00
nmlgc 5afee78f33 [Decompilation] [th01] Konngara: Loading and entrance animation
It's script-like code, what can you say. Maybe minimally sloppy in some
places, but ultimately harmless.

Oh, the Siddhaṃ seed syllables are supposed to show up immediately, with
no delay between them? Good to know – clocking your emulator too low
tends to roll them down from the top of the screen, and does add a
noticeable delay between the individual images.

… Wait, but this means that ZUN could have *intended* this "effect".
Why else would he not only put those syllables into four individual
images, but also show them on the foreground VRAM page?

Completes P0141, funded by [Anonymous] and rosenrose.
2021-05-27 19:36:03 +02:00
nmlgc 6c21ba15dc [Decompilation] [th01] Konngara: Pellet spawn ray rendering
Part of P0141, funded by [Anonymous] and rosenrose.
2021-05-27 19:36:03 +02:00
nmlgc eba61444ce [Decompilation] [th01] Boss entities: Outer loading function
ASM land had a macro for this, which suggested a corresponding inlined
class method in C++ land. We couldn't use that macro for Konngara's
third boss entity though. So I probably wanted to wait with that inline
function until the decompilation of that Konngara load call, which
could verify the existence of said inline function. And it did!

Part of P0141, funded by [Anonymous] and rosenrose.
2021-05-27 19:36:02 +02:00
nmlgc 2406533713 [Contributing] Officially decide on UTF-8 as the default encoding
It's been like this since the beginning, I just hadn't written it down.
So yeah, sorry to everyone who likes to edit code in period correct
90's DOS terminal editors.

Part of P0141, funded by [Anonymous] and rosenrose.
2021-05-27 19:35:59 +02:00
nmlgc 3e2104a164 [Maintenance] [th02] Move the packfile name constant to th02/shiftjis/
Now you can grep for it¹!

¹ Editor that's actually smart enough to not only correctly detect
  Shift-JIS during grepping, but also match the characters in a search
  regardless of file encoding, sold separately

Part of P0141, funded by [Anonymous] and rosenrose.
2021-05-27 19:35:02 +02:00
nmlgc 241b61e808 [Maintenance] Distinguish between Shift-JIS and gaiji strings
The main point of the previous strings/ subdirectory was to bundle all
hardcoded strings for translators. And sure, *technically*, gaiji
strings are *both* strings *and* something you might want to translate.
But mainly, they're sprites with an attached enum, and their own
directory. Changes to the enum quickly tend to involve changes to the
strings that use these values, so it makes sense to keep both in the
same directory.

Especially since 82% of the previous strings/ directories consisted of
such gaiji strings.

That leaves the strings/ directory rather empty and nondescript though.
Recently though, I've been wanting to generally move all Shift-JIS text
to this directory. While that wouldn't *solve* the typical "text editor
accidentally a file upon save, due to wrongly detected encoding" issue,
it's at least a mitigation: If all Shift-JIS strings are in files that
contain nothing *but* Shift-JIS strings, a wrongly detected encoding
becomes immediately noticeable.

For that job, strings/ can have a more descriptive name though. Hence,
shiftjis/.

Part of P0141, funded by [Anonymous] and rosenrose.
2021-05-27 19:10:26 +02:00
nmlgc 68d9419e8e [Maintenance] [th02] Remove ranks_center[data].asm
Part of P0141, funded by [Anonymous] and rosenrose.
2021-05-27 19:08:57 +02:00
nmlgc d856f7df16 [Reverse-engineering] [th01] Escape sequences
We've got to move all of Konngara's escape sequences to C land right
now, to get them out of the way of the filenames, so we might as well
look at all of them, in the entire binary.

But, uh… "graph mode"? That one is severely underdocumented, seemingly
even in Japanese. Turns out that it's a way to disable Shift-JIS
decoding, which makes it possible to access the half-width glyphs in
the PC-98 font ROM at the 0x81-0x9F and 0xE0-0xFF codepoints.
(In regular "kanji mode", these are interpreted as Shift-JIS lead
bytes.)
So, I did a deep dive into NEC's IO.SYS to hunt down all places where
this distinction has an effect, and then implemented it into DOSBox-X,
which was still missing everything related to it:

	https://github.com/joncampbell123/dosbox-x/pull/2547

If P0140 looks a bit empty as a result, that's why – most of the
feature work went into DOSBox-X, not ReC98. That's the beauty of
"anything" pushes. :tannedcirno:

So, after switching to graph mode, TH01 does… one of the slowest
possible memset()s over all of text RAM (one printf(" ") call for every
single one of its 80×25 half-width cells), before switching back to
kanji mode. What a waste of RE time…? Oh well, at least we've now got
plenty of documentation to prove to future port authors that these
weird escape sequences *actually* do nothing.

Completes P0140, funded by [Anonymous].
2021-05-27 18:49:29 +02:00
nmlgc 8fe3338587 [Decompilation] [th01] Unused, player shot/pellet-related boss stage flag
At least that's what we can infer from its position in the code.
Putting it into player shots for the sole reason that it's easier to
find it there.

Part of P0140, funded by [Anonymous].
2021-05-27 18:49:29 +02:00
nmlgc 00ca4ccc1f [Maintenance] Add a COMPONENT_COUNT constant for RGB colors
sizeof(RGB4), seriously?! That's *so* wrong. And also inconsistent next
to COLOR_COUNT everywhere.

Part of P0140, funded by [Anonymous].
2021-05-27 18:49:29 +02:00
nmlgc e5dffdd9b6 [Maintenance] [th01] Move frame_delay() to consistently named files
It didn't bother me during all of 2020 that TH01's version was
inconsistently part of vsync.h?!

Part of P0140, funded by [Anonymous].
2021-05-27 18:49:29 +02:00
nmlgc d9858113d8 [Decompilation] [th04] snd_load()
Last one! Done with the SHARED segment for the forseeable future! 🎉

Sure, not the best C++ code either, but still by far the sanest
implementation of this function in any of the 4 games.

Completes P0139, funded by [Anonymous].
2021-05-12 14:31:03 +02:00
nmlgc cd96b039fa [Maintenance] Use a dedicated enum for snd_load()'s function parameter
It's not a kaja_func_t if it's shifted left by 8 bits. Why is it
shifted left by 8 bits to begin with, though? Why not just pass a
kaja_func_t, and assign it to AH? Arrrrgh.

Part of P0139, funded by [Anonymous].
2021-05-12 14:31:02 +02:00
nmlgc 46a1674250 [Reverse-engineering] [th02/th03/th04/th05] snd_load() buffer size
Hardcoding these *might* have been acceptable if the numbers actually
matched the sizes defined in GAME.BAT, but they don't. With PMD's
AH=22h function, there's really no excuse though.
About time I looked into this, and expressed that constant as an inline
function that can easily be replaced with a proper implementation.

Part of P0139, funded by [Anonymous].
2021-05-12 14:31:00 +02:00
nmlgc ca4bf5002a [Separate translation units] [th04] cdg_put_plane() (undecompilable)
Reason: Self-modifying. -.-

Part of P0139, funded by [Anonymous].
2021-05-11 18:48:00 +02:00
nmlgc 62e0167e20 [Translation unit catch-up] [th03/th04/th05] snd_delay_until_measure(), game_exit_to_dos()
Segment alignment issues once again… but that completes the SHARED
segments of all TH03 and TH05 binaries, for now!

Part of P0139, funded by [Anonymous].
2021-05-11 18:48:00 +02:00
nmlgc 78df46af1f [Decompilation] [th04/th05] snd_determine_modes()
ZUN apparently had no trust in the sanity of Turbo C++'s code
generation?

Part of P0139, funded by [Anonymous].
2021-05-11 18:47:59 +02:00
nmlgc 14cb1d3665 [Maintenance] Document relevant return values of PMD's AH=09h function
I'll leave a comprehensive, fully documented enum to interested
contributors, since that would involve research into basically the
entire history of the PC-9800 series, and even the clearly out-of-scope
PC-88VA. After all, PC-98 Touhou only needs to distinguish "OPN- /
PC-9801-26K-compatible sound sources handled by PMD.COM" from
"everything else", since all other PMD varieties are OPNA- /
PC-9801-86-compatible.

Part of P0139, funded by [Anonymous].
2021-05-11 18:47:58 +02:00
nmlgc d8ece227fd [Separate translation units] [th04] cdg_put_nocolors_8() (undecompilable)
Reason: Self-modifying. -.-

Part of P0139, funded by [Anonymous].
2021-05-11 18:47:58 +02:00
nmlgc 7761f4e804 [Decompilation] [th04] snd_kaja_interrupt()
4 games, 4 different versions of this function. Interestingly,
moving the game-specific differences to inline functions makes it
obvious that this function was only intended for BGM, not sound
effects.

Part of P0139, funded by [Anonymous].
2021-05-11 18:47:57 +02:00
nmlgc 4c0e76ab89 [Decompilation] [th04/th05] snd_mmd_resident()
Part of P0139, funded by [Anonymous].
2021-05-11 18:47:57 +02:00
nmlgc 4c8a3cb353 [Decompilation] [th04/th05] snd_pmd_resident()
Part of P0139, funded by [Anonymous].
2021-05-11 18:47:56 +02:00
nmlgc acd29854c7 [Decompilation] KAJA driver ISR magic check
Down to one inline ASM instruction for these.

Part of P0139, funded by [Anonymous].
2021-05-11 18:47:55 +02:00
nmlgc 8e16481e27 [Translation unit catch-up] [th04] vector1_at(), vector2_at()
Part of P0139, funded by [Anonymous].
2021-05-11 18:47:54 +02:00
nmlgc 794c6ab55c [Maintenance] Fix another bunch of accumulated typos
Part of P0139, funded by [Anonymous].
2021-05-11 18:47:49 +02:00
nmlgc 864e8643ab [Decompilation] [th04] .MPN: Load function
Basically just a copy of the TH02 one, adjusted to work with multiple
slots.

Completes P0138, funded by [Anonymous] and Blue Bolt.
2021-04-22 19:27:48 +02:00
nmlgc aaa37c7081 [Decompilation] [th04] input_wait_for_change(), .MPN: Freeing / palette setting
Another three functions in one commit, forced by segment alignment…

Part of P0138, funded by [Anonymous] and Blue Bolt.
2021-04-22 19:27:08 +02:00
nmlgc cfaa20694a [Reverse-engineering] [th04] .MPN: Slot structure
TH04 is the only game that reserves memory for 8 .MPN slots, despite
only actually using just one of them, like all other games… And there
goes another 458 bytes of conventional RAM.

Part of P0138, funded by [Anonymous] and Blue Bolt.
2021-04-22 19:25:44 +02:00
nmlgc b1cf7ee021 [Maintenance] [th02] .MPN: Update existing decompilations to current standards
Part of P0138, funded by [Anonymous] and Blue Bolt.
2021-04-22 19:25:01 +02:00