Commit Graph

713 Commits

Author SHA1 Message Date
nmlgc 30e6b7c3db [Maintenance] Correctly declare all input functions
The pascal calling convention for TH03's input mode functions actually
sort of matters, since we have this nice function pointer type that
expects pascal.
2019-11-30 19:34:55 +01:00
nmlgc a6a805f008 [ZUN symbols] key_det / shiftkey
Not applying this leak to TH03 since it would have more than one
`key_det` variable, resulting in names that are as much fanfiction as
the current ones…
2019-11-30 19:32:10 +01:00
nmlgc 73f5ae79a0 [Reverse-engineering] [th03] Demo frame counter
My dumb parser identified this as a reference to the PI header slots,
which is why it's here now!

Completes P0060, funded by Touhou Patch Center.
2019-11-28 23:23:30 +01:00
nmlgc 5bffab4f43 [Position independence] [th04/th05] Remaining references to PI slots
Part of P0060, funded by Touhou Patch Center.
2019-11-28 23:23:30 +01:00
nmlgc 619203a1c9 [Position independence] [th02/th03/th04/th05] Color palettes
Part of P0060, funded by Touhou Patch Center.
2019-11-28 23:23:29 +01:00
nmlgc b6e0330ff6 [Decompilation] [th03] Sprite display calls
Yes, decompilation, of something that was so obviously originally
written in ASM. We're still left with two un-decompilable instructions
here, but I'm amazed at how nicely I was able to abstract away all of
the gory register details, leading to pretty clear, readable, and dare
I say *portable* code?! Turbo C++ was once again pretty helpful here:

• `static_cast<char>(_BX) = _AL` actually compiles into `MOV BL, AL`,
  as you would have intended,
• and no-op assignments like _DI = _DI are optimized away, allowing
  us to leave them in for clarity, so that we can have all parameter
  assignments for the SPRITE16 display call in a single place.

I love this compiler.

Part of P0060, funded by Touhou Patch Center.
2019-11-28 23:14:21 +01:00
nmlgc 2269d0c29c [Reverse-engineering] [th03] Playfield sprite clipping coordinates
Part of P0060, funded by Touhou Patch Center.
2019-11-28 23:12:10 +01:00
wintiger0222 29385dd7cb [Naming] [th02] text_wipe 2019-11-24 16:02:43 +01:00
wintiger0222 61a2df2d71 [Naming] [th04/th05] EMS area setup 2019-11-24 16:02:43 +01:00
wintiger0222 37fb6eba32 [Naming] [th02/th04/th05] Demo loading and playback 2019-11-24 14:14:13 +01:00
nmlgc 7c80fb01f2 [Contributing] Establish how to cite ZUN's source code leaks 2019-11-24 14:14:13 +01:00
wintiger0222 22bf71d170 [Reduction] [th03/th04/th05] game_init_main 2019-11-24 14:14:13 +01:00
wintiger0222 9b9f487d6c [Naming] [th03/th04/th05] graph_putsa_fx
Let's cover this one during decompilation.
2019-11-24 14:14:05 +01:00
wintiger0222 09edcab744 [Reduction] [th03/th04/th05] game_init_op 2019-11-24 14:04:36 +01:00
nmlgc 71c737c4ee [Maintenance] Move DOS memory assignment sizes to separate files
Ideally, these could be calculated from some other game-specific
parameters? Anyone else who wants to look into this?
2019-11-24 14:04:36 +01:00
nmlgc 3f25caa5df [Reverse-engineering] [th02/th03/th04/th05] DOS memory assignment sizes
Changing the variable suffix to _paras rather than _siz here, since
master.lib uses the latter for byte sizes, while these are paragraphs.
2019-11-24 14:04:34 +01:00
wintiger0222 0009c3c161 [Reduction] [th03/th04/th05] game_exit_to_dos 2019-11-24 12:45:25 +01:00
wintiger0222 34b7b61964 [Reduction] [th03/th04/th05] game_exit 2019-11-24 12:45:17 +01:00
wintiger0222 5f0b2642ea [Maintenance] Fix #include syntax for mdrv2.c 2019-11-24 12:45:08 +01:00
nmlgc e9453bffe0 [Contributing] Add a rule against decompiling self-modifying code
Will come up soon in TH03, actually.
2019-11-20 00:22:43 +01:00
nmlgc afbc7eb381 [Contributing] Add some welcoming words for new contributors
And the explicit permission to also do something as seemingly trivial
as naming functions or data on separate branches, which apparently
still needed to be said somewhere.
2019-11-20 00:22:26 +01:00
nmlgc c196cdb41e [Contributing] Fix a few minor typos and omissions 2019-11-19 23:09:36 +01:00
nmlgc 8b627803a3 [Position independence] Vector calls and variables
Raw, uninteresting position independence work. Or maybe not, given that
this was one of the few things that also apply to TH01, and reveal just
how chaotically this game was coded. And so we've got three ways that
ZUN stored regular 2D points: Regularly (X first, Y second), Y first
and X second, and multiple points stored in a structure of arrays…

Completes P0059, funded by [Anonymous] and -Tom-.
2019-11-18 22:24:24 +01:00
nmlgc 550bba9b3c [Position independence] False positives in master.lib EGC function calls
Mostly used for screen shaking.

Part of P0059, funded by [Anonymous] and -Tom-.
2019-11-18 22:21:34 +01:00
nmlgc 3d7211b128 [Position independence] Remaining motion structures and comparisons
Part of P0059, funded by [Anonymous] and -Tom-.
2019-11-18 22:21:29 +01:00
nmlgc ad22ce26c2 [Reverse-engineering] [th04/th05] Player position clamping
Part of P0059, funded by [Anonymous] and -Tom-.
2019-11-18 22:21:23 +01:00
nmlgc b37611b1be [Maintenance] Add an underscore to the player_pos variable
No need to declare them as `pascal` on the C side only because I messed
up when naming them first.

Part of P0059, funded by [Anonymous] and -Tom-.
2019-11-18 22:21:15 +01:00
wintiger0222 01de2900dd [Decompilation] [th01] frame_delay
Closes #7.
2019-11-18 21:29:43 +01:00
nmlgc fef0299fbc [Reverse-engineering] [th04/th05] Midboss / boss explosion phase constants
In the end, the explosions remain the only constant in these phases,
everything else ("defeat"? "last phase"?) could have been
misunderstood. And yes, the algorithm really treated these 111
constants as potential memory references…

Completes P0058, funded by -Tom-.
2019-11-14 00:57:38 +01:00
nmlgc 6c4852f789 [Position independence] False positives in master.lib GRCG function calls
Yup, function parameters that can clearly be identified as coordinates
are by far the fastest way to raise the calculated position
independence percentage. Kinda makes it sound like useless work, which
I'm only doing because it's dictated by some counting algorithm on a
website, but decompilation will want to un-hex all of these values
anyway. We're merely doing that right now, across all games.

Part of P0058, funded by -Tom-.
2019-11-14 00:51:48 +01:00
nmlgc 8a250701bd [Reverse-engineering] [th04/th05] Items dropped when losing a life
> not using the Point structure, which is not only perfectly suitable
here, but would have also generated much better code

Part of P0058, funded by -Tom-.
2019-11-14 00:50:56 +01:00
nmlgc ac7540dada [Reverse-engineering] [th04/th05] Item types and sprite IDs
Completes P0057, funded by [Anonymous] and -Tom-.
2019-11-14 00:49:22 +01:00
nmlgc 2f0ca1ccf1 [Position independence] False positives in item functions
Welcome to this new [brand] of reverse-engineering, where we only fix
things that might be mistaken for addresses, without looking deeper
into what the actual functions do… unless that directly leaps into
the eye.

Part of P0057, funded by [Anonymous] and -Tom-.
2019-11-14 00:48:24 +01:00
nmlgc 34089cbe3f [Reverse-engineering] [th04/th05] Item structure
Part of P0057, funded by [Anonymous] and -Tom-.
2019-11-14 00:47:20 +01:00
nmlgc 2918e6dbd0 [Reverse-engineering] [th04/th05] Item spawn "splash" circles
"Splashes"? That's what uth05win calls them. Oh well, "circle" is
already taken, and merely keeping the slices in the item/ directory
won't avoid the name collision when looking at game code.

These are hardly visible on top of regular enemy explosion animations;
you can most clearly see them at the end of the TH04 Extra Stage
midboss. Easy enough to *almost* completely cover right now, even
during a position independence push. Struct strITEM_SPLASH in uth05win.

Part of P0057, funded by [Anonymous] and -Tom-.
2019-11-14 00:45:32 +01:00
nmlgc d1acb70cdc [Maintenance] Move the enemy item drop table to an item/ subdirectory
Part of P0057, funded by [Anonymous] and -Tom-.
2019-11-14 00:44:10 +01:00
nmlgc 1cb97310c7 [Readme] Remove the porting plans
Well, that might have been my entire sales pitch for the decompilation,
and now I've ruined everything… Still, I've been getting way too many
confused questions about this by now. Let's focus on reconstructing,
and once that's done, ReC98 is done, and another project can take over.
Maybe done by me and mostly following the original plans, but probably
not.

Thanks to -Tom- for finally pushing me to do this 😛
2019-11-12 20:42:21 +01:00
nmlgc a2e8866c28 [Readme] Clarify that the library % numbers only apply to the two main ones
Apparently, people might have misunderstood this to mean "we've found
SPRITE16, so TH03 is now 74% (OP) / 54% (MAIN) done"? Thanks to
Splashman for the tip.
2019-11-12 19:50:41 +01:00
nmlgc c09446a1f4 [Reverse-engineering] [th03] SPRITE16 calls
Aha! TH03's in-game graphics run in line-doubled 640×200 simply because
that's what this SPRITE16.COM version was written for, making use of
the PC-98 EGC for optimized blitting.

Doesn't seem all *too* optimized though, given that it chooses to
effectively draw every sprite twice, just in case it might overlap with
something that's already in VRAM. It first clears the previous VRAM
content at the drawing position according to the sprite's alpha mask,
then ORs in the actual sprite data. The EGC can do monochrome alpha-
tested blitting just as well as the GRCG, but once the sprite data
covers all bitplanes, ORing is apparently the best it can do by itself?
More technical details on the raster operations in the next push!

Completes P0056, funded by rosenrose and [Anonymous].
2019-11-06 23:36:47 +01:00
nmlgc 772897c8f5 [th03] Identify ZUNSP.COM as a rebrand of Promisence Soft's SPRITE16.COM driver
Which was actually found out by @m1yur1 last year, who thankfully
tweeted this in reference to ReC98:

	https://twitter.com/m1yur1/status/1018855232371998720

Thanks a lot! But what makes this more than a piece of trivia is the
fact that the StormySpace release actually *was* bundled with
documentation. Shoutout to the Neo Kobe PC-98 collection for preserving
the original release! This should now greatly simplify any RE efforts
related to TH03's INT 42h calls. (Not *trivialize*, because there's
still all this EGC hardware to be understood…)

And sure, you *were* allowed to use this driver in your own game, but
replacing the copyright with your own isn't exactly the nicest thing to
do… That now makes three library programmers that ZUN didn't credit.
Makes me wonder what makes M. Kajihara so special. Probably the fact
that Touhou has always been about the music for ZUN, first and
foremost.

Part of P0056, funded by rosenrose and [Anonymous].
2019-11-06 23:30:43 +01:00
nmlgc b28cefc1c1 [Readme] Start a separate contribution guideline file 2019-11-04 22:33:53 +01:00
Egor 0460072f25 [Decompilation] [th01] mdrv2_resident
I thought this would be a good target for my first attempt at
decompilation. Should have known something was up, because it's the only
undecompiled proc in the translation unit.

Oh well, SCOPY stands for "structure copy" anyway. /s
2019-11-04 22:14:10 +01:00
Egor 61252e83f5 [Maintenance] gitignore everything in bin 2019-11-02 19:22:05 +02:00
nmlgc 34e3c7e530 [Readme] Add crowdfunding / progress badges and a GitHub funding button
Are we cool now?
2019-10-17 20:58:50 +02:00
nmlgc e7e1cbcaaf [Decompilation] [th05] Marisa's shot control functions
Yeah… such fun pretending that the original code wasn't copy-pasted.
And yes, Reimu will have to wait until the next one.

Completes P0037, funded by zorg.
2019-10-14 23:54:37 +02:00
nmlgc 1276a0c94a [Decompilation] [th05] Mima's shot control functions
And if I don't manage to cover Reimu in this push, it's because ZUN
switched around the cases in half of the functions here… 😵  Here's
some macros instead, to make the code at least *look* as table-driven
and readable as it should have been in the first place.

Part of P0037, funded by zorg.
2019-10-14 23:54:37 +02:00
nmlgc da27eb4c31 [Decompilation] [th05] Yuuka's shot control functions
Ooh, shot position being determined by RNG at lower shot levels? That's
some RNG manipulation TAS potential right there! Maybe.

Part of P0037, funded by zorg.
2019-10-14 23:54:29 +02:00
nmlgc db4de240e9 [Decompilation] Prepare the C side for the shot type control functions
That should make this convoluted copypasta a bit easier to read. And
sure, I could have done something about the loop as well, but
SHOT_FUNC_INIT already hides enough control flow behind a macro…

Part of P0037, funded by zorg.
2019-10-14 23:42:20 +02:00
nmlgc 82b0e1db24 [Reverse-engineering] [th05] Player shot cycle bitflags
A TH05 innovation that actually makes the game code easier to read?!
Although it was quite hard to actually reverse-engineer it, with the
confusing flag ordering pointing to some deeper meaning behind the
flags, which really doesn't exist.

Completes P0036, funded by zorg.
2019-10-14 23:42:09 +02:00
nmlgc a84fa33beb [Reverse-engineering] [th04/th05] Player shot cycle counter
Part of P0036, funded by zorg.
2019-10-14 23:42:02 +02:00