Commit Graph

992 Commits

Author SHA1 Message Date
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 ec478666de [Position independence] [th01] graph_2xscale_byterect_1_to_0_slow() calls
It's actually not that easy to find memory references in REIIDEN.EXE
that can both be quickly be RE'd at the end of a push, and which also
aren't more sensibly handled by immediate decompilation. So, have more
false positive busywork…

Part of P0095, funded by Yanga.
2020-05-31 17:31:18 +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 6b2a54d8d2 [Position independence] [th01] Final false positives in OP.EXE and FUUIN.EXE
100% PI for both! Now, where are all the modders who wanted to replace
MDRV2 with PMD… because you can now prototype that, without worring
about x86 instruction lengths, at least inside the main menu.

Part of P0095, funded by Yanga.
2020-05-31 17:29:05 +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 e1a728f9e3 [Position independence] [th01] Remaining graph_printf_fx() calls
Part of P0095, funded by Yanga.
2020-05-31 17:25:14 +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 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 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 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 e1f3af547f [Maintenance] [th04/th05] Declare null callbacks in a single place in C land
Part of P0089, funded by [Anonymous] and Blue Bolt.
2020-05-04 16:14:18 +02:00
nmlgc 8b58e193bd [Maintenance] Reorganize gaiji definitions
Part of P0089, funded by [Anonymous] and Blue Bolt.
2020-05-04 00:05:32 +02:00
nmlgc 5531ed9b8b [Maintenance] [th04/th05] Declare scrolling variables and functions in C land
Part of P0089, funded by [Anonymous] and Blue Bolt.
2020-05-04 00:03:51 +02:00
nmlgc 708d9fc8ac [Maintenance] [th02/th04/th05] Declare more stage and player symbols in C land
Part of P0089, funded by [Anonymous] and Blue Bolt.
2020-05-04 00:03:17 +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 17434fe848 [Decompilation] [th04/th05] Declare stage tile data and functions in C land
tiles_invalidate_around() must have had the hardest function signature
to figure out in all of PC-98 Touhou… because it seems impossible to
handle all three ways of passing parameters. No way around separately
declaring it in every translation unit then, with the parameter list
expected by that segment's code generation.

Part of P0089, funded by [Anonymous] and Blue Bolt.
2020-05-03 23:52:30 +02:00
nmlgc bf40b4e375 [Maintenance] [th04/th05] Declare GRCG register setting functions in C land
Part of P0089, funded by [Anonymous] and Blue Bolt.
2020-05-03 23:38:32 +02:00
nmlgc 7db8821c41 [Maintenance] [th04/th05] Declare public text popup symbols in C land
Part of P0089, funded by [Anonymous] and Blue Bolt.
2020-05-03 23:32:12 +02:00
nmlgc 021280b25c [Maintenance] Don't modify master.h to #undef grcg_off() for TH02
Because TH04 and TH05 actually do use this macro.

Part of P0089, funded by [Anonymous] and Blue Bolt.
2020-05-03 23:30:47 +02:00
nmlgc 624b66f3ca [Maintenance] [th04/th05] Add a segment split before the title popup functions
A bit tricky with those ASM translation units near-calling functions in
the very first segment, and #pragma codeseg requiring an additional
group parameter to correctly calculate array offsets (including those
used for `switch` statements). But doable.

Part of P0089, funded by [Anonymous] and Blue Bolt.
2020-05-03 23:28:25 +02:00