Commit Graph

124 Commits

Author SHA1 Message Date
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 40b8325cc3 [Maintenance] [th01] Move MDRV2 files to a separate `snd/` directory
Consistency… even though we won't have more of those in this game.

Part of P0098, funded by Yanga.
2020-06-13 21:15:30 +02:00
nmlgc 9ef56ad5ca [Reverse-engineering] [th01] Player shot class
Part of P0098, funded by Yanga.
2020-06-13 21:15:29 +02:00
nmlgc 600f036c04 [Reverse-engineering] [th01] Portal-related orb flags and variables
Completes P0097, funded by Ember2528.
2020-06-13 21:15:29 +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 f364dc0182 [Reverse-engineering] [th01] Orb position
… Wow, the orb is *actually* only ever displayed at byte-aligned X
coordinates, divisible by 8. It's only thanks to the constant spinning
that its movement appears at least *somewhat* smooth.

(And yeah, this is purely a rendering issue; internally, its position
*is* tracked at pixel precision.)

Part of P0097, funded by Ember2528.
2020-06-13 21:13:51 +02:00
nmlgc 8283c5eec8 [Decompilation] [th01] .PTN: Unaligned 16×16 blitting
But no corresponding unblitting function…?

Completes P0096, funded by Ember2528.
2020-06-13 21:13:50 +02:00
nmlgc 979f401515 [Maintenance] [th01] .PTN: Define the transparent color in a single place
Inlined template functions! \o/

Part of P0096, funded by Ember2528.
2020-06-13 21:13:50 +02:00
nmlgc 9cd54f1b13 [Decompilation] [th01] .PTN: Byte-aligned 16×16 blitting
Part of P0096, funded by Ember2528.
2020-06-13 21:13:49 +02:00
nmlgc f6c668dafc [Decompilation] [th01] .PTN: Byte-aligned 16×16 unblitting
Part of P0096, funded by Ember2528.
2020-06-13 21:13:49 +02:00
nmlgc 71970f57c6 [Decompilation] [th01] .PTN: Byte-aligned 32×32 blitting
Part of P0096, funded by Ember2528.
2020-06-13 21:13:49 +02:00
nmlgc a55c5ced81 [Decompilation] [th01] .PTN: Byte-aligned 32×32 unblitting
Part of P0096, funded by Ember2528.
2020-06-13 21:13:48 +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 94dc9ef251 [Maintenance] Move the pellet sprite to TH01
That's where it actually originated.

Part of P0096, funded by Ember2528.
2020-06-12 21:49:16 +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 416aa4ccef [Reverse-engineering] [th01] .BOS bitplane pointers
No idea why ZUN split the 6 slots into 4 with a regular alpha plane,
and 2 with a negated alpha plane. The latter are only used for Sariel's
animations.

Part of P0095, funded by Yanga.
2020-05-31 17:31:07 +02:00
nmlgc 55b3cb0330 [Decompilation] [th01] Main menu: White line animation
> "Sure, this is a PI push, but this second-to-last set of PI false
  positives so small, let's immediately decompile it ^.^"
> Time taken: 22 minutes
Nice when this works out!

Part of P0095, funded by Yanga.
2020-05-31 17:27:37 +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 026fff63a5 [Decompilation] [th01] Ending picture loading and display
Aww, how far we've come with inlining and helpful macros.

Part of P0094, funded by Yanga.
2020-05-25 15:18:44 +02:00
nmlgc a7230ba26a [Maintenance] Move the EGC copy setup function to a separate file
Too bad we still have to bother with renaming the function via #define
in the few cases where an executable contains two or more copies of
this function. We can't just make it `static`, since TH02 MAINE.EXE
actually does far-call it from a different segment (and thus,
translation unit).

Part of P0094, funded by Yanga.
2020-05-25 15:17:41 +02:00
nmlgc 5c77db08ca [Decompilation] [th01] High score registration
Completing the high score menu with a final stupid set of
inconsistencies between REIIDEN.EXE and FUUIN.EXE. Oh well.

Part of P0094, funded by Yanga.
2020-05-25 15:16:40 +02:00
nmlgc 753e1b670a [Decompilation] Change graph_move_byterect_interpage() page parameters to int
Turbo C++ doesn't do the 32-bit PUSH LARGE optimization for 8-bit
parameters?

Part of P0094, funded by Yanga.
2020-05-25 15:15:41 +02:00
nmlgc 3bd824b5be [Maintenance] [th01] Add a header for the slow 2× rectangle scale function
Part of P0094, funded by Yanga.
2020-05-25 15:14:19 +02:00
nmlgc 0e73029276 [Decompilation] [th01] High score menu: Name entering loop
The REIIDEN.EXE version (which is only shown when game-overing) has a
completely invisible timeout that force-enters a high score name after
1000... *keyboard inputs*? Not frames? Why. Like, how do even you
realistically to such a number.
(Best guess: It's a hidden easter egg to amuse players who place
drinking glasses on cursor keys. Or beer bottles.)

And hey, that initialization of the name variable with ASCII spaces.
The only actually meaningful byte-wise access… except that it's not,
because ZUN could have just used the Shift-JIS ideographic space for
the exact same effect.

Completes P0093, funded by Ember2528.
2020-05-25 15:11:12 +02:00
nmlgc bbef9b0bdb [Decompilation] [th01] REYHI*.DAT saving
Now with POSIX file I/O in both executables. And the confirmation that
the name array is indeed exclusively accessed per-byte.

Part of P0093, funded by Ember2528.
2020-05-25 15:10:07 +02:00
nmlgc 6e0c33a8bf [Decompilation] [th01] High score menu: Input handling
It's exactly as terrible as you would have expected after hearing
"alphabet cursor actually stored as on-screen position". Nothing gained
in reducing redundancy any further here, any meaningful change would
pretty much have to rewrite the entire thing.

Part of P0093, funded by Ember2528.
2020-05-25 15:07:59 +02:00
nmlgc 440330857a [Decompilation] [th01] High score menu: Shot key handling
In which inline functions are apparently the only way to trick Turbo
C++ into not actually optimizing away the useless `AND AL, 0FFh`.

But come on. Just accessing the high score name characters in chunks of
16-bit Shift-JIS codepoints (which is what they are!) instead of
breaking them down to bytes *everywhere* would have been both more
readable (no swapping of Shift-JIS literals, no bitshifts), more
efficient (this isn't running on an 8-bit CPU after all), and less of a
waste of my time…

Completes P0092, funded by Yanga.
2020-05-25 15:06:48 +02:00
nmlgc 7a1332e1f5 [Decompilation] [th01] High score menu: Re-rendering individual characters
Lol, the internal alphabet cursor position is actually stored as the
on-screen top-left position of the selected character, which this
function then maps back to a character index. At least that gets rid of
quite a bunch of PI false positives now.

Part of P0092, funded by Yanga.
2020-05-25 15:05:43 +02:00
nmlgc 57be510056 [Decompilation] [th01] High score menu: Initial table rendering
With ternary operator expressions straight out of Jigoku.
(TL note: Jigoku means hell.)
Nice to see that Turbo C++ apparently has no nesting limit on function
call inlining in general, though!

Part of P0092, funded by Yanga.
2020-05-25 15:03:55 +02:00
nmlgc 8473dc2048 [Maintenance] [th01] Rethink high score menu constants
The one thing where I didn't think ahead…

Part of P0092, funded by Yanga.
2020-05-25 14:59:23 +02:00
nmlgc 16ac6b4206 [Decompilation] [th01] High score menu: Initial alphabet rendering
Completes P0091, funded by Ember2528.
2020-05-12 15:06:12 +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 651d09f5bd [Decompilation] [th01] Keyboard input in FUUIN.EXE
The only TH01 executable not supporting the numpad?

And that's the point where you just rewrite the distinct input_prev_*
values as a single array, because they're local to input_sense()
anyway.

Part of P0091, funded by Ember2528.
2020-05-12 15:06:11 +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 07dab293ad [Decompilation] [th01] Input declarations shared between REIIDEN and FUUIN
Of which we can express precisely *nothing* as an inline function,
because Turbo C++ always emits a useless `JMP SHORT $+2` at the end of
such an inlined function if it contains nested `if` statements. This is
also what forced some of the functions in 90252cc to be expressed as
macros. By now, this is clear enough to be documented separately.

And to warrant this separate commit.

Completes P0090, funded by Yanga.
2020-05-12 15:05:49 +02:00
nmlgc 389b9a1056 [Decompilation] [th01] Keyboard input in OP.EXE
Starting with the odd one out, the one that doesn't use master.lib and
has two input sense functions: one for the main menu, and one for the
option window.

Both of which also immediately perform the ring arithmetic on the menu
cursor variable… because there's nothing else to be done with these
inputs in OP.EXE? Separating input sensing from processing apparently
wasn't all too obvious of a thought, and it's only truly done in TH02
and later.

Part of P0090, funded by Yanga.
2020-05-12 14:55:09 +02:00
nmlgc 7ad14db394 [Decompilation] [th01] REIIDEN.CFG loading and saving
That's where the backwards `goto` for .CFG file error handling
originated!

Part of P0090, funded by Yanga.
2020-05-12 14:36:43 +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 97ce7b78cd [Maintenance] Consistently use forward slashes in #include paths
Completes P0087, funded by -Tom-.
2020-04-15 21:34:32 +02:00
nmlgc d1f3dcd620 [Maintenance] Move all features exclusive to MAIN.EXE to a main/ subdirectory
Adding op/, main/, and end/ directories does nicely cover a great
majority of the "not really further classifiable slices" implied in
d56bd45.

Part of P0086, funded by [Anonymous] and Blue Bolt.
2020-04-15 20:58:01 +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
nmlgc c338305a61 [Decompilation] REYHI*.DAT loading and recreation
With master.lib file I/O in REIIDEN.EXE, and POSIX file I/O in
FUUIN.EXE… yup.

Part of P0084, funded by Yanga.
2020-03-22 10:16:08 +01:00
nmlgc ee9168b7eb [Reverse-engineering] [th01] REYHI*.DAT structure
Part of P0084, funded by Yanga.
2020-03-22 10:01:16 +01:00
nmlgc 1cc9cefa26 [Decompilation] [th01] PTN-sized page 0→1 copies
Final shared function in TH01's OP.EXE.

Part of P0084, funded by Yanga.
2020-03-22 09:59:24 +01:00
nmlgc dfac2f2fd4 [Position independence] [th01] EGC-powered page 1→0 region copy calls
12.4 fixed-point subpixels, in TH01?

Completes P0083, funded by Yanga.
2020-03-18 20:33:59 +01:00
nmlgc 9e676ce3ef [Decompilation] [th01] .PTN snap functions
Which repurpose the .PTN image slots to store the background of
frequently updated VRAM sections, like all the numbers in the HUD.
Future games would simply use the text RAM and gaiji for numbers. Which
would have worked just fine for TH01 as well (especially since all the
functions we've seen so far are aligned to the 8-pixel byte grid), but
it looks as if ZUN simply wasn't aware of gaiji during the development
of TH01.

Part of P0083, funded by Yanga.
2020-03-18 20:33:58 +01:00
nmlgc a184413f27 [Decompilation] [th01] .PTN file loading and non-transparent display
What is this, error checking in a ZUN game?! And surprisingly good code
for deriving the alpha plane?!

Part of P0083, funded by Yanga.
2020-03-18 20:33:58 +01:00