Commit Graph

112 Commits

Author SHA1 Message Date
nmlgc 60ee6e94fc [Decompilation] [th01] 32×32 square inversion on a single bitplane
The main effect behind the discoloration seen in the bomb animation,
as well as the exploding squares at the end of Kikuri's and Sariel's
entrance animation.

Single-function segments are lovely, by the way!

Part of P0121, funded by Yanga.
2020-09-28 13:05:07 +02:00
nmlgc 453dd3ca7e [Decompilation] [th05] Starting the game
And that's the intended way to play back the hidden DEMO5.REC. Unlock
the Extra Stage with all 4 characters, then hold the left and right
arrow keys in the main menu while waiting the usual demo replay.

For a recording of that replay, see

	https://www.youtube.com/watch?v=iP2ywlW2u4U

Completes P0119, funded by [Anonymous] and -Tom-.
2020-09-21 15:00:44 +02:00
nmlgc 3c27fbc3bd [Decompilation] [th05] Player character selection menu
The TH04 one might have the same function structure, but the only thing
that's actually identical in both games is the picture darkening loop.

Part of P0119, funded by [Anonymous] and -Tom-.
2020-09-21 15:00:05 +02:00
nmlgc 791d6d6085 [Build] [th04/th05] 16-bit: Rebuild ZUN.COM by default
Shoutout to Egor, who already implemented the necessary wrappers in
2018, which means that I don't have to spend a push on that. 🙂

Part of P0117, funded by [Anonymous].
2020-09-16 22:30:56 +02:00
nmlgc c5852610f6 [th05/gjinit] Initial state
And with that, we finally dumped every single PC-98 Touhou binary!
Since it'd be overkill to merge bmp2arr into the re-baseline branch
though, we also have to start out with the raw image bytes here.

Part of P0117, funded by [Anonymous].
2020-09-16 22:29:55 +02:00
nmlgc 9695c8d277 [th05/memchk] Initial state
No libc anymore, yet still no memory freeing…?

Part of P0117, funded by [Anonymous].
2020-09-16 22:29:35 +02:00
nmlgc 90b7ace180 [th04/memchk] Initial state
Needlessly linked with TCC rather than TLINK, adding almost 4 KB of
completely unnecessary libc startup code.

Or maybe not, since ZUN doesn't free the allocated memory himself, but
relies on libc to do that?

Part of P0117, funded by [Anonymous].
2020-09-16 22:20:34 +02:00
nmlgc 197202d8ee [th05/zuninit] Initial state
On the surface, Version1.02 of the `INTvector set program` seems to
be largely the same as Version1.01, just with fancier instructions,
some redundancy removed, and some slightly different wording in the
playful messages… or is there more to it? Stay tuned!

Part of P0117, funded by [Anonymous].
2020-09-16 22:17:18 +02:00
nmlgc f54cd0fe95 [th04/zuninit] Initial state
Yup, it's finally the right time to properly rebuild ZUN.COM. While
all of these small binaries would still need some RE attention, putting
in the few minutes to make them position-independent right now is
definitely worth it. Adding them to the PI calculation on the website
would take much longer 😅

Part of P0117, funded by [Anonymous].
2020-09-16 22:16:49 +02:00
nmlgc 03048c318d [Decompilation] [th04/th05] Cutscenes: Text blending
Completes P0116, funded by [Anonymous] and Lmocinemod.
2020-09-12 12:09:31 +02:00
nmlgc 4e6bedf20d [Decompilation] [th05] Staff roll: Space window coordinates
Part of P0115, funded by Lmocinemod and Blue Bolt.
2020-09-12 11:21:44 +02:00
nmlgc 967bb8b633 [Decompilation] [th03] Input mode and delay functions
Nice to see that Borland C++ optimizes bit-tests to cover just the high
or low byte of a word if possible, and that these don't have to be
two-byte structures after all.

Completes P0114, funded by Lmocinemod.
2020-09-07 21:18:40 +02:00
nmlgc aee8a13958 [Separate translation units] [th02] game_exit_to_dos(), zun_error(), graph_putsa_fx()
Oh, wait. Due to ridiculously unlucky alignment, we can't actually
approach TH03's OP.EXE from the top of code segment 2… without
covering way too many functions at once, that is.
At least TH02 works out with "just" three functions at once. *If* we
add seg2 back to OP.EXE, where we previously needed to delete it… 😵

Part of P0114, funded by Lmocinemod.
2020-09-07 21:18:40 +02:00
nmlgc 716a925636 [Decompilation] [th03] YUME.CFG loading and saving
Oh, I just needed something in TH03's OP.EXE before code segment 2.

Part of P0114, funded by Lmocinemod.
2020-09-07 21:18:40 +02:00
nmlgc 5a6ac29f50 [Separate translation units] [th03] CDG: Non-alpha display (undecompilable)
Reason: Self-modifying. -.-

Part of P0114, funded by Lmocinemod.
2020-09-07 21:18:39 +02:00
nmlgc ecc1372842 [Decompilation] [th03] Lookup table for horizontally flipping planar pixels
In which we exchange variable names for the ability to decompile more
than just 3 instructions here.
… yeah, "decompilation" is still a stretch.

Part of P0114, funded by Lmocinemod.
2020-09-07 21:18:38 +02:00
nmlgc 6204fdd450 [Separate translation units] [th02/th03/th04] frame_delay_2()
Completes P0113, funded by Lmocinemod.
2020-09-07 21:18:38 +02:00
nmlgc f0511221b7 [Maintenance] [th02/th03/th04/th05] Establish a common name for code segment 2
About time I finally developed this piece of tech. Towards TH05, this
segment got more and more undecompilable ASM functions mixed inbetween
C ones. Which means that pretty much all of the current ASM land
`#include`s in that segment will have to become translation units. And
we *really* don't want an additional layer of numbered, per-binary
translation units that just `#include` maybe one or two functions.

Also yeah, no _TEXT suffix, to drive home the point that this is a
"library" segment, and not really "owned" by any one file.

Part of P0113, funded by Lmocinemod.
2020-09-07 21:18:38 +02:00
nmlgc 1f1847de48 [Build] Assemble all .ASM files in the 32-bit build part
Yeah, why *were* we assembling them in the 16-bit part before?!
Possible reasons:
• In a time before Tup, it made no actual difference whether these
  little files were assembled in the 32-bit or 16-bit part. Now it sort
  of does, since we've temporarily given up on minimal rebuilds in the
  16-bit part.
• Emphasizing the temporary nature of the 32-bit part by deliberately
  moving everything to the 16-bit part as early as possible?
• It all started with the ZUN.COM ASM code, which doesn't include any
  other files, and can therefore be perfectly tracked by a Makefile.
  Which *was* superior than the exclusive dumb batch file we had in the
  past. And then I've simply cargo-culted all new .ASM translation
  units into the 16-bit part well.

Oh, and another positive side effect of temporarily not using 16-bit
TASM: The build process now also runs on Windows 95.

Part of P0113, funded by Lmocinemod.
2020-09-07 17:25:56 +02:00
nmlgc 51b775bd41 [Build] 16-bit: Don't explictly specify the .OBJ extension in TASM rules
If the output file already exists, TASM interprets a filename with
extension as a directory, and then concatenates the implicitly
generated output file name to that path… yup.

Part of P0001, funded by GhostPhanom.
2020-09-03 19:04:16 +02:00
nmlgc e5f28204a5 [Build] 32-bit: Actually create `bin/Pipeline` during the 32-bit part -.-
Lol, this led the bmp2arr compilation to fail on a clean checkout.
Lesson learned: Always test on a clean clone, not in your separate test
repo that you just `git pull` up to the final commit in a push, but
with all the build artifacts still in there…

Also, yes, `mkdir` only supports backslashes.

Part of P0001, funded by GhostPhanom.
2020-09-03 19:04:15 +02:00
nmlgc 4ef4c9eeb0 [Maintenance] [th05] Split segment #1 before Reimu's bomb star animation
Nope, not going to figure this one out on ASM level.

Completes P0111, funded by [Anonymous] and Blue Bolt.
2020-08-28 15:08:21 +02:00
nmlgc 1c3e9097cc [Decompilation] [th05] EX-Alice: Fire wave management
Final unknown entity in TH05 that can collide with the player!
Get position independence hype!
(Also, no structure member comments necessary, thanks to the new
types!)

Part of P0111, funded by [Anonymous] and Blue Bolt.
2020-08-28 14:59:27 +02:00
nmlgc 7c4d31c02b [Decompilation] [th05] Line sets: Rendering
With all the memmove()-style shifting of individual lines, there's
probably a point to reserving 20 lines per set, but only ever rendering
4 of them. We'll see once I get to decompile all of these functions.

Part of P0110, funded by [Anonymous] and Blue Bolt.
2020-08-19 20:10:08 +02:00
nmlgc 2c7d86bc5b [Decompilation] [th05] Mai & Yuki: Smooth random movement
Wow, so the boss_stuff_t structure did exist in the original code after
all. This is the only function in all of TH04 and TH05 that confirms
it – in dea40ad, it just seemed like something I made up, out of
convenience.

Completes P0109, funded by [Anonymous] and Blue Bolt.
2020-08-16 21:41:34 +02:00
nmlgc 4f7a3a28c3 [Reverse-engineering] [th05] Difficulty- and rank-based bullet pattern tuning
If C allowed labels of other functions as `goto` targets, this *might*
have been decompilable into something useful to modders. But like this,
there's no point in even trying.

Yeah, you *really* don't want to base your fangame mod on TH05.

Part of P0109, funded by [Anonymous] and Blue Bolt.
2020-08-16 21:40:33 +02:00
nmlgc 829946a29e [Decompilation] [th04] Difficulty- and rank-based bullet pattern tuning
Because it's at least *possible* to decompile TH04's version of these
functions.

Part of P0109, funded by [Anonymous] and Blue Bolt.
2020-08-16 21:40:32 +02:00
nmlgc 0644857fcb [Decompilation] [th05] Bosses: Smoothly flying towards a point
Found a uth05win inaccuracy! Once the Y coordinate gets close enough to
the target point, it actually speeds up twice as much as the X
coordinate would. This might make uth05win a couple of frames slower in
all boss fights from Stage 3 on.

And yeah, got too used to decompilation to go back to splitting off
RE'd functions in ASM land 😛

Part of P0109, funded by [Anonymous] and Blue Bolt.
2020-08-16 21:40:31 +02:00
nmlgc 5f5eb8aa4e [Decompilation] [th01] .BOS: Unused and broken plane pointer reset function
Because that's not how you free dynamically allocated memory?

Part of P0106, funded by Yanga.
2020-08-12 17:49:34 +02:00
nmlgc 72538610ba [Decompilation] [th01] .GRC: Load function
Still no idea what those 7 unknown bytes in the .GRC and .BOS headers
could be.

Part of P0105, funded by Yanga.
2020-08-12 16:19:39 +02:00
nmlgc a75e0f8f53 [Maintenance] Compile all VRAM-accessing translation units as C++
Leading to slight complications in TH02's Music Room and shot type
selection menus. Thought about leaving those in C for a while, but I
still think it's worth it for the consistency we get with the VRAM
offset functions. Also, we'll have similar code for the main menus of
later games, and I'll surely won't be using C++ when starting out with
these.

Part of P0105, funded by Yanga.
2020-08-12 16:16:09 +02:00
nmlgc afd74fb8aa [Decompilation] [th01] 16-bit integer to string conversion
"Hey, let's have separate functions for uint16_t and int16_t… and then
just *not* support negative numbers in the latter" :zunpet:

Part of P0104, funded by Ember2528.
2020-07-27 17:22:16 +02:00
nmlgc edb70162e0 [Decompilation] [th01] Pellets: Manager class constructor
Note how Turbo C++ auto-generates that call to `operator new`, which
you don't see in the decompilation anymore. So yeah, as soon as you add
a constructor, Turbo C++ enforces heap allocation for any instance of
that class, even function-local ones that would otherwise be
stack-allocated.

That's where the bad reputation of C++ comes from, I guess?

Part of P0102, funded by Yanga.
2020-07-12 16:23:12 +02:00
nmlgc e3a78bd19b [Maintenance] Fix vector creation function declarations and calls
Part of P0099, funded by Ember2528.
2020-07-12 15:22:50 +02:00
nmlgc 3e3129567c [Decompilation] [th01] Pellet delay cloud blitting and unblitting
And immediately, we discover another two hardcoded sprites, with, of
course, another set of functions for blitting and unblitting them…

Part of P0099, funded by Ember2528.
2020-07-12 15:15:05 +02:00
nmlgc 442a92d32b [Decompilation] [th01] Player shots: Spawn function
Continuing to learn new things about Turbo C++'s code generation!

Part of P0098, funded by Yanga.
2020-06-13 21:15:31 +02:00
nmlgc 51de73bcc9 [Decompilation] [th01] Orb physics
"Physics". Not only did ZUN restrict the X velocity to the 5 discrete
states of -8, -4, 0, 4, and 8 (because hey, unaligned blitting is slow
anyway?), but gravity is also only applied every 5 frames.

We're still missing quite a bit of usage code, but these are the core
functions. One of which turned out to be undecompilable, due to… a
rigorously defined instruction order when performing arithmetic between
`double`s and `float`s?! Still, spelling out all this stuff in ASM
seems much better than somehow splitting the data segment, just so that
we can immediately use literals there.

Part of P0097, funded by Ember2528.
2020-06-13 21:15:27 +02:00
nmlgc 6a5fa3aee9 [Maintenance] [th01] Decide on `unput` for VRAM page 1 pixel restoration
"Unblitting" reads better in commit descriptions, though 🤔

Part of P0096, funded by Ember2528.
2020-06-13 21:13:48 +02:00
nmlgc 52b8414993 [Reverse-engineering] [th01] Reimu's X position
13 copies of the clamping branches… Quality.

Part of P0096, funded by Ember2528.
2020-06-13 21:13:47 +02:00
nmlgc dd89843fae [Decompilation] [th01] Pellet rendering
So even TH01 wasn't 100% C++ after all. Turns out that this function
was the only instance in all of REIIDEN.EXE where ReC98 previously had
different encodings for identical x86 instructions.

Part of P0096, funded by Ember2528.
2020-06-13 21:11:53 +02:00
nmlgc 8ddb77801d [Decompilation] [th01] GDC-powered graphics layer scrolling
Surprise, it's the (terribly suboptimal) setgsta() example function
from the PC-9801 Programmers' Bible! 100% identical, so ZUN must have
read that book as well.
Used for screen shaking effects, as well as the scrolling backgrounds
at the start of the Final Boss stages.

Completes P0095, funded by Yanga.
2020-05-31 17:46:46 +02:00
nmlgc 57a8487084 [Decompilation] [th01] FUUIN.EXE resident structure data retrieval
Completes P0094, funded by Yanga.
2020-05-25 15:22:53 +02:00
nmlgc 29c5a7365f [Build] Assemble piloadc as a separate translation unit
Restoring the originally released version here as well… except for
ZUN's custom format magic ID, of course.

Completes P0091, funded by Ember2528.
2020-05-12 15:06:13 +02:00
nmlgc 4f87ec8152 [Decompilation] [th01] Blitting full-width numbers onto VRAM
Part of P0091, funded by Ember2528.
2020-05-12 15:06:12 +02:00
nmlgc f2543c8336 [Decompilation] [th01] Keyboard input in REIIDEN.EXE
Yes, TH01's memory info screen will recurse into itself for every 3
frames the PgUp key is held, requiring one additional PgDown press per
recursion to actually get out of it.
You can, of course, also crash the system via a stack overflow this
way, if that's your thing.

Part of P0091, funded by Ember2528.
2020-05-12 15:06:11 +02:00
nmlgc 05a0e9b1c8 [Decompilation] [th01] Unused function to snap all dots with hardware color #4
That's… pretty specific. The only thing on the main menu with this
color is the "1996 ZUN" text at the bottom… probably part of an
effect that we never got to see. Every other idea would be baseless
speculation, given that the snapped buffer isn't used anywhere else.

Part of P0090, funded by Yanga.
2020-05-11 22:12:51 +02:00
nmlgc 90252cc59a [Decompilation] [th04/th05] Stage and BGM title popups
Completes P0089, funded by [Anonymous] and Blue Bolt.
2020-05-04 16:14:21 +02:00
nmlgc 70b4134af4 [Maintenance] [th04/th05] Assemble 16-bit .ASM files case-sensitively
Otherwise, TASM would simply convert all EXTRN declarations in those
files to uppercase. Then, the linker would expect them in uppercase,
forcing both the case-sensitive big 32-bit .ASM files *and* the entire
C land to declare them as uppercase as well.

For functions with __pascal convention which are always uppercased
anyway, this makes no difference. It does matter for regular __cdecl
variables, though, and the C declaration of [score_delta] in e6294c2
already showed that we'd then be forced to use macros if we wanted to
pretend that these names still had lowercase characters.

Doing this for every variable referenced in both C land and 16-bit ASM
land gets annoying quickly. So, no need to force this inconsistency if
we can get rid of it by slightly uglifying ASM land.

Part of P0089, funded by [Anonymous] and Blue Bolt.
2020-05-03 23:56:08 +02:00
nmlgc 02f0a0afcc [Build] Don't word-align everything by default
Again, 11 necessary workarounds, vs. forcing byte aligment in at least
18 places, and that number would have significantly grown in the
future.

Part of P0085, funded by -Tom-.
2020-04-03 17:35:57 +02:00
nmlgc ffad8cc897 [Build] Use the minimum possible size for enums by default
5 enums where code generation wants an `int`, vs. 11 cases where using
the minimum size is exactly the right default. So it's way more
idiomatic to force those 5 to 16 bits via a dummy element… except that
we can't give it a single, consistent name, because you can't redeclare
the same element in a different enum later.

Oh well, let's have this ugly naming convention instead, which makes it
totally clear that the force element not, in fact, a valid value of
that enum.

Part of P0085, funded by -Tom-.
2020-04-03 17:33:58 +02:00