Commit Graph

887 Commits

Author SHA1 Message Date
nmlgc 0252da2a71 [Decompilation] [th01] Game init and exit functions
Yes, that's the code that forgot reactivating the text cursor before
returning to the DOS prompt!

Completes P0080, funded by Ember2528 and Splashman.
2020-03-03 13:12:00 +01:00
nmlgc f56725f3d0 [Maintenance] [th01] Move ztext.c to the hardware/ directory
And fix a typo from 2015 that hasn't actually mattered yet.

Part of P0080, funded by Ember2528 and Splashman.
2020-03-03 13:08:33 +01:00
nmlgc de3f9ec31b [Decompilation] [th01] Graphics BIOS initialization and activation functions
Just like with the z_text_*() functions, master.lib doesn't already
have graph_init() and graph_exit() either, and once again, ZUN's code
here doesn't fully correspond to any master.lib function. Unlike the
z_text_*() functions though, those names aren't really the best
descriptions for these rather random combinations of BIOS calls and I/O
port writes…

Anyway, that's the entire segment!

Part of P0080, funded by Ember2528 and Splashman.
2020-03-03 13:07:55 +01:00
nmlgc ee682ce2e1 [Decompilation] [th01] Page flipping
No macros here either.

Part of P0080, funded by Ember2528 and Splashman.
2020-03-03 13:07:29 +01:00
nmlgc 14f9bc3bbe [Decompilation] [th01] Basic hardware palette and GRCG functions
No macros for the port numbers here! Anyone who will try to read and
understand this code will probably want to look those up in PC-98
hardware documentation, and macros would just be an annoying layer of
indirection then.

Part of P0080, funded by Ember2528 and Splashman.
2020-03-03 13:06:34 +01:00
nmlgc 0e852feee8 [Decompilation] [th01] Whole-page color fills and copies
Page… 2? On a system with only page 0 and 1? Had to get out my real
PC-98 to double-check that I wasn't missing anything here, since
every emulator only looks at the bottom bit of the page number. But
real hardware seems to do the same, and there really is nothing special
to it semantically, being equivalent to page 0. 🤷

Part of P0080, funded by Ember2528 and Splashman.
2020-03-03 13:05:49 +01:00
nmlgc 7d77338e29 [Decompilation] [th01] Palette fades from and to white and black
Nice lambda functions.

Part of P0080, funded by Ember2528 and Splashman.
2020-03-03 13:04:49 +01:00
nmlgc 3229b2285d [Decompilation] Encode the per-component range in the RGB color template
Allowing us to then retrieve it using a function call with no run-time
cost, although we do have to be careful with the types here.
Also, is that another solution to decompilation puzzles that involve
types of number literals?

Part of P0080, funded by Ember2528 and Splashman.
2020-03-03 13:02:30 +01:00
nmlgc f2b454dfc6 [Decompilation] Overload operator[] for palettes
Which has no run-time cost in almost all cases.

Part of P0080, funded by Ember2528 and Splashman.
2020-03-03 13:01:27 +01:00
nmlgc cd48aa351e [Position independence] [th02/th04/th05] False positives in input constants
Completes P0079, funded by -Tom-.
2020-02-29 16:01:13 +01:00
nmlgc 8a9cb158b6 [Reverse-engineering] [th05] Custom entity 6: Shinki's 32×32 balls
Which need to be separate from Mai's and Yuki's 32×32 balls because…
they have a delay cloud, whose radius absolutely has to be stored
redundantly, rather then deriving it from the [age]? Same for the decay
frame count. And the _update() function was copy-pasted from the knife
one…

Part of P0079, funded by -Tom-.
2020-02-29 16:00:30 +01:00
nmlgc 1764700729 [Reverse-engineering] [th05] Custom entity 5: Yumeko's knives
Immediately understandable just by applying the structure fields.

Part of P0079, funded by -Tom-.
2020-02-29 15:57:18 +01:00
nmlgc 3bcc62ecbc [Position independence] [th05] Custom entity 4: Mai's and Yuki's 32×32 balls
Part of P0079, funded by -Tom-.
2020-02-29 15:56:03 +01:00
nmlgc 9e52cb15cf [Reverse-engineering] [th05] Custom entity 3: Curve bullet head structure
"Wait, the template has to store the color… hey, let's just overload
the sprite ID field!" :zunpet:

Completes P0078, funded by iruleatgames and -Tom-.
2020-02-29 15:55:17 +01:00
nmlgc dba8f15dc7 [Position independence] [th05] Custom entity 2: Alice's puppets
Heavily hardcoded for only two of them, even though there'd be space
for 65, even without position independence. Puppet army mod when?

Part of P0078, funded by iruleatgames and -Tom-.
2020-02-29 15:54:09 +01:00
nmlgc 42f2dd790b [Position independence] [th05] Custom entity 1: Stage 2 star particle structure
Part of P0078, funded by iruleatgames and -Tom-.
2020-02-29 15:53:32 +01:00
nmlgc 5000bc07d7 [Reverse-engineering] [th05] Custom entity structure
On the surface, TH05 uses one single 26-byte structure for
• the Stage 2 starfield,
• Alice's puppets,
• curve bullet heads,
• Mai's snowballs and Yuki's fireballs,
• Yumeko's knives,
• and Shinki's 32×32 bullets.
But looking closer, it turns out that the fields of all these have very
different semantics, and in some cases, even different types. uth05win
treated all of those as distinct structures, and we're going to do the
same, merely overlaying the pointers onto the same generic array.

Part of P0078, funded by iruleatgames and -Tom-.
2020-02-29 15:51:17 +01:00
nmlgc 012a84de1f [Reverse-engineering] [th05] Curve bullet trail structure
7 individually moving curve bullets × (16 trail points + 1 head point)
= 117 effective hitboxes. And yes, the game only renders half of them.

Part of P0078, funded by iruleatgames and -Tom-.
2020-02-29 15:47:37 +01:00
nmlgc f4eb7a8445 [Maintenance] Throw out the Borland C++ run-time slices 🎉
This cautionary tale of wasted time will now be told at

	https://github.com/nmlgc/Slices

with additional context for anyone else thinking about starting their
own ReC project.

Completes P0077, funded by Splashman and -Tom-.
2020-02-23 17:53:19 +01:00
nmlgc f99d7a571c [Maintenance] Remove all dependencies on Borland C++ run-time source headers
And with all possible .COM executables decompiled, this set of changes
reaches an acceptable scope, allowing us to *finally*…

Part of P0077, funded by Splashman and -Tom-.
2020-02-23 17:53:18 +01:00
nmlgc ebd214bbb2 [Decompilation] [th05] RES_KSO.COM
And of course, TH05 ruins the consistency once again. Sure, the added
file error handling is nice, but we also have changes in the playful
messages (lol), and now need a third distinct optimization barrier
(🤦)… But as it turns out, inlined calls to empty functions work as
well. They also seem closer to what ZUN might have actually written
there, given that their function body could have been removed by the
preprocessor, similar to the logging functions in the Windows Touhou
games. (With the difference that the latter infamously *aren't*
inlined…)

Part of P0077, funded by Splashman and -Tom-.
2020-02-23 17:53:17 +01:00
nmlgc 4e53b97552 [Decompilation] [th04] RES_HUMA.COM
Part of P0077, funded by Splashman and -Tom-.
2020-02-23 17:53:17 +01:00
nmlgc a1c3acd9f1 [Maintenance] [th04/th05] Declare BGM and SE modes in C land
Part of P0077, funded by Splashman and -Tom-.
2020-02-23 17:53:17 +01:00
nmlgc 803c079a5d [Decompilation] [th03] RES_YUME.COM
Huh, C++ wants its `char`s to be unsigned in order to *not* sign-extend
them to 16 bits for comparison against ASCII literals?!
Anyway, that completes TH03's ZUN.COM, with bascially no new C code.

Part of P0077, funded by Splashman and -Tom-.
2020-02-23 17:53:16 +01:00
wintiger0222 381db0a14d [Reverse-engineering] [th04/th05] Dialog box background rendering
Let's go with "box", since a frame is a unit of time --Nmlgc
2020-02-23 17:53:16 +01:00
nmlgc a2961b02da [Reverse-engineering] [th03/th04/th05] Configuration file
The supposedly low-hanging fruit that almost every outside contributor
wanted to grab a lot earlier, but (of course) always just for a single
game… Comprehensively covering all of them has only started to make
sense recently 😛

Also, yes, the variable with the uppercase .CFG filename has itself a
lowercase name and vice versa…

Part of P0077, funded by Splashman and -Tom-.
2020-02-23 17:24:17 +01:00
nmlgc c5a18ecfa0 [Naming] [th02/th04/th05] Maximum and default starting lives and bombs
Oh wow, caff4fe introduced wrong bytes into RES_KSO.COM by confusing
[cfg_bombs] with [credit_lives] -.- Which I didn't find out back then
because all the RES_*.COM binaries still had some different instruction
encodings anyway and I just didn't care enough to base my diff of those
files on the wrong encoding versions to notice the bug…
Whoops.

Part of P0077, funded by Splashman and -Tom-.
2020-02-23 17:22:46 +01:00
nmlgc e4816a0baf [Maintenance] [th05] Fix local variable names in op_animate() -.-
Part of P0077, funded by Splashman and -Tom-.
2020-02-23 17:20:30 +01:00
nmlgc ee2e385d57 [Maintenance] [th04/th05] Correctly declare player variables
Part of P0077, funded by Splashman and -Tom-.
2020-02-23 17:19:21 +01:00
nmlgc 9ae9754fb3 [Maintenance] [th02] Move .CFG/resident initialization to separate files
All future RES_*.COM binaries reuse this code.

Completes P0076, funded by [Anonymous] and -Tom-.
2020-02-23 17:14:43 +01:00
nmlgc f8d83eefa3 [Maintenance] [th03] Move cfg.h to the formats/ directory
Part of P0076, funded by [Anonymous] and -Tom-.
2020-02-23 17:13:03 +01:00
nmlgc b8ca607c38 [Decompilation] [th02] Get zun_res1.c right
4½ years after aa56a7c, it turns out that the correct decompilation
involves… no-ops generated by assigning variables that just happen to
be in registers to themselves?! Which does get optimized out, but only
after TCC folded identical tail code in all branches of a function,
thus effectively functioning as an optimization barrier.

The initial attempt used register pseudovariables, but this definitely
is the best possible way this could work – portable, and doesn't
unnecessarily shred the code into tiny inlined functions pieces. The
mindblowing thing here is that ZUN could have actually written this to
have additional, albeit unnecessary, lines to place breakpoints on. But
that means he must have chosen those two local variables in SI and DI
completely by chance… 🤯

The best thing though? ~#pragma inline is gone~

Part of P0076, funded by [Anonymous] and -Tom-.
2020-02-23 17:12:35 +01:00
nmlgc 942373e640 [Maintenance] [th02] Split ZUN_RES.COM into three translation units
Necessary to make string literals from the first one end up at their
correct positions in the data segment even after the upcoming
deduplication…

Part of P0076, funded by [Anonymous] and -Tom-.
2020-02-23 17:12:26 +01:00
nmlgc a1f36ffa04 [Reverse-engineering] [th03] Demo initialization
Something small that came out of the resident structure review.
Including more research to suggest that we probably can't ever use C++
constructors for anything in ReC98.

Part of P0076, funded by [Anonymous] and -Tom-.
2020-02-23 16:58:30 +01:00
nmlgc 484730e319 [Reverse-engineering] [th03] Resident structure, reviewed
Now with the correct types, more consistency with the other games with
some field names (rank, is_cpu, rand, bgm_mode, demo_num), and some
more research to improve some of the TH03-specific fields.

Part of P0076, funded by [Anonymous] and -Tom-.
2020-02-23 16:57:35 +01:00
32th System 93c580065a [Reverse-engineering] [th03] Resident structure
From https://gist.github.com/32th-System/855bb05d791ecb6aba63a01e26b92f51.
2020-02-23 16:57:29 +01:00
nmlgc f288ba4c8c [Maintenance] [th03] Move character speed declarations to a separate header
More include reduction…

Part of P0076, funded by [Anonymous] and -Tom-.
2020-02-23 16:56:39 +01:00
nmlgc b7ea95836d [Maintenance] [th03/th04/th05] Start a new "essential macros" file
Both player/player.hpp and resident.hpp (in case of TH03's PLAYER_COUNT)
and th04/shared.hpp (in case of TH04/TH05's MAIN_STAGE_COUNT) have way
too much additional stuff that we don't want to include everywhere we
need these constants. So let's try this "no types allowed" approach
instead… maybe that'll work out for once.

Part of P0076, funded by [Anonymous] and -Tom-.
2020-02-23 16:56:15 +01:00
nmlgc ff777a099e [Decompilation] [th03] Add a type for the paletted playchar IDs
Much better than the previous incorrect comment, since the char_id()
method now easily generates the correct sequence of conversion
instructions, seen all throughout the ASM. Even within array
subscripts!

Part of P0076, funded by [Anonymous] and -Tom-.
2020-02-23 16:56:14 +01:00
nmlgc 6363a37d7a [Maintenance] Move TH02's sound functions to a separate header
Oh hey, guarding declarations with complicated types via #ifdef limits
the header files we additionally have to #include!

Part of P0076, funded by [Anonymous] and -Tom-.
2020-02-23 16:51:45 +01:00
nmlgc 222fc993d0 [Reverse-engineering] [th04/th05] Bullet spawn types
Well… how else to call a variable that handles
• pellet vs. 16×16 sprite (TH04),
• the delay cloud flags from bullet_spawn_state_t, but with different
  values (which is restricted to 16×16 sprites in TH04),
• optionally showing the gather animation before spawning the bullet
… whether the bullet uses the basic slowdown motion (TH05),
  (which is restricted to pellets in TH04),
• and defining what happens *after* the gather animation – not actually
  spawning any bullets (TH04), or using the special motion type from
  the bullet template (TH05)

🤯

Completes P0075, funded by Myles and -Tom-.
2020-02-16 21:48:33 +01:00
nmlgc f21269f373 [Reverse-engineering] [th04/th05] Bullet template structure
Turns out that angles are more clearly expressed in hex after all. And
if we use negative values for everything greater than 80h, we still
remove those from the PI calculation.

*Really* not sure about using that delta union in the TH04 one though.
Might be saner to just hide the complexity of the technically two
separate types after all… Let's see.

Part of P0075, funded by Myles and -Tom-.
2020-02-16 21:47:53 +01:00
nmlgc 3292af086b [Reverse-engineering] [th04/th05] Bullet pattern types
uth05win TL note: "n-way all-around" means "ring"… yep, let's better
improve on the naming here, once again using established terminology
from Sparen's Danmaku Design Guide at

	https://sparen.github.io/ph3tutorials/ddsga3.html

Since TH04 only supports rings *or* spreads *or* stacks, overloading
[delta] to store both spread angle and stack speed, that enum does
serve kind of a purpose in TH04. Unlike TH05, where it could be vastly
simplified to a bitfield with 4 flags: aim to player, randomize angle,
randomize speed, force single. Which could then actually create *more*
types of patterns than these uselessly defined 14 distinct types, all
of which can already be derived from the other values of the upcoming
template structure:
• Set [stack] to 1 if you don't want a stack
• Set [spread] to 1 if you don't want a spread
• Set [spread_delta_angle] to 0 to turn a N-way spread into a ring
Easy.

Part of P0075, funded by Myles and -Tom-.
2020-02-16 21:47:28 +01:00
nmlgc 1807906400 [Reverse-engineering] [th04/th05] Sprite selection for angled bullets
Completes P0074, funded by Myles.
2020-02-16 21:46:43 +01:00
nmlgc eb0cf6820f [Reverse-engineering] [th04/th05] Bullet-related sprite IDs
IDs based on Maribel Hearn's jargon page
(https://maribelhearn.com/jargon) as well as Sparen's Danmaku Design
Guide (https://sparen.github.io/ph3tutorials/ddsga1.html#sub2).

Part of P0074, funded by Myles.
2020-02-16 21:44:51 +01:00
nmlgc d6f356da45 [Maintenance] Use a single per-game, per-binary file for super_*() patnum IDs
Since they're determined by the order of sprites in a .BFT file,
they're best auto-generated by an enum as much as possible.

Part of P0074, funded by Myles.
2020-02-16 21:43:08 +01:00
nmlgc fdf2a45baf [Maintenance] Use *_CELS to denote the number of distinct animation sprites
Which are typically lower than the amount of *_FRAMES they're shown in.

Part of P0074, funded by Myles.
2020-02-16 21:41:28 +01:00
nmlgc 52864172a4 [Reverse-engineering] [th05] Micro-optimized monochrome 16×16 sprite display
Might as well cover this one while I've got this type of function in my
head. This one is used for the animated star backgrounds during Stage 2
and the Shinki battle.

Completes P0073, funded by [Anonymous] and -Tom-.
2020-02-16 21:39:27 +01:00
nmlgc 38f17af25d [Reverse-engineering] [th04/th05] Micro-optimized 32×32 sprite display
Which *looks* like a master.lib function, but only because ZUN adapted
his own micro-optimized super_roll_put_tiny() for 32×32. Good thing we
covered that one first!

Part of P0073, funded by [Anonymous] and -Tom-.
2020-02-16 21:38:38 +01:00
nmlgc e4f1718e93 [Maintenance] [th04/th05] Improve the z_super_roll_put*() naming convention
So, master.lib has:
• super_put_tiny() for tiny-format 16×n sprites
• super_roll_put_tiny() for vertically wrapped tiny-format 16×16
  sprites
• super_put_tiny_small() for tiny-format 8×n sprites
• yet *no* super_roll_put_tiny_small() function

And now we have ZUN adding micro-optimized versions of:
1) vertically-wrapped tiny-format 16×16, clearly based on master.lib's
   super_roll_put_tiny(), RE'd in 35f9bd7
2) vertically-wrapped tiny-format 32×32
3) vertically-wrapped non-tiny monochrome 16×16 (TH05 only)

Conclusion: Even though 1) does duplicate a master.lib function, trying
to continue following master.lib's inconsistent naming convention only
leads to more confusion here. master.lib also already designates the _8
suffix to mean "x will be byte-aligned, ⌊x/8⌋*8"…
So let's:
• spell out both coordinates of the sprite size directly in the
  function
• keep the z_ prefix to encode ZUN's optimized calling convention
  (left/top coordinates in registers, ES already set to the beginning
  of a VRAM plane, GRCG already on) for all of these, not just 1).
• and prefix the actual functions with _raw, since C land will want
  to handle the coordinate parameter registers in a macro.

Part of P0073, funded by [Anonymous] and -Tom-.
2020-02-16 21:36:56 +01:00