Commit Graph

860 Commits

Author SHA1 Message Date
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
nmlgc 0f3359e1b3 [Maintenance] Use @@locals for self-modifying code in bfnt_entry_pat()
Which finally allows us to use the PLANE_SIZE macro in ASM land. Yeah,
(ROW_SIZE * RES_Y) has finally got old.

Part of P0073, funded by [Anonymous] and -Tom-.
2020-02-16 21:35:16 +01:00
nmlgc cea3ea6dc7 [Reverse-engineering] [th04/th05] Bullet structure
And since everyone always cares about caps:
• TH04: 240 for the white 8×8 pellets, 220 for 16×16 sprites
• TH05: 180 for the white 8×8 pallets, 240 for 16×16 sprites

Completes P0072, funded by [Anonymous] and -Tom-.
2020-02-16 21:32:30 +01:00
nmlgc 1568121f05 [Position independence] [th04/th05] Remaining switch jump tables
Part of P0072, funded by [Anonymous] and -Tom-.
2020-02-16 21:29:54 +01:00
nmlgc 4bb04abb6f [Reverse-engineering] [th03] Player structure
Completes P0071, funded by KirbyComment and -Tom-.
2020-01-29 09:14:00 +01:00
nmlgc 245fc55b63 [Maintenance] [th03] Fix playchar_t enum syntax -.-
Part of P0071, funded by KirbyComment and -Tom-.
2020-01-29 09:13:02 +01:00
nmlgc ed3763b591 [Reverse-engineering] [th03] Shot-related enums
Part of P0071, funded by KirbyComment and -Tom-.
2020-01-29 09:12:17 +01:00
nmlgc e478ceef87 [Reverse-engineering] [th03] Hyper function pointers
夢時空.TXT calls this a "Gauge Power-Up", but that's both misleading
and too verbose, so let's go with how scoreplayers call it.

Part of P0071, funded by KirbyComment and -Tom-.
2020-01-29 09:11:41 +01:00
nmlgc 5ad9d83686 [Reverse-engineering] [th03] Charge Shot function pointers
The _add function pointer is part of the 128-byte player structure,
that's why it's already named differently here 🙃

Part of P0071, funded by KirbyComment and -Tom-.
2020-01-29 09:10:20 +01:00
nmlgc e6601fb27f [Reverse-engineering] [th03] Stage-dependent additional CPU damage per hit
Yup, in the first 6 stages, the CPU always takes more damage per hit
than P1. 1½ hearts in stages 1 and 2, 1 heart in stages 3 and 4, and
½ heart in stages 5 and 6.

Part of P0071, funded by KirbyComment and -Tom-.
2020-01-29 09:10:18 +01:00
nmlgc 327021bf16 [Position independence] [th03] Hit combo ring buffer
Completes P0070, funded by KirbyComment.
2020-01-20 22:49:33 +01:00
nmlgc 17cbe2ad62 [Reverse-engineering] [th03] Combo structure
Hey, look, it's a 0FFFFh constant that *doesn't* get RE'd as -1!

Part of P0070, funded by KirbyComment.
2020-01-20 22:49:31 +01:00
nmlgc 9943f2f7ef [Reverse-engineering] [th03] Currently processed player ID
Probably going to refine those `pid_other` variables later; it almost
seems as if there's one to store the attacked player for every entity
type?

Part of P0070, funded by KirbyComment.
2020-01-19 22:11:01 +01:00
nmlgc 8924a4a0aa [Reverse-engineering] [th03] Current score manipulation
Little-endian BCD, again… Far less crazy than in TH04 and TH05,
though, thanks to updating and rendering being two different functions
here.

Part of P0070, funded by KirbyComment.
2020-01-19 22:10:11 +01:00
nmlgc 761a0f48a2 [Reverse-engineering] [th03] Five-digit powers of 10
Part of P0070, funded by KirbyComment.
2020-01-19 22:08:58 +01:00
wintiger0222 a93175828c [Reverse-engineering] [th03] In-game score font
More related to the TH05 Music Room piano label font than to the small
popup numbers --Nmlgc
2020-01-19 22:07:31 +01:00
nmlgc 2bfd7be787 [Contributing] Document how to use TASM's interfaced function call syntax
And officially allow the stdcall workaround for __cdecl calls with
optimized stack cleanup.
2020-01-19 22:05:45 +01:00
nmlgc 3a2b26c370 [Contributing] BSS padding bytes should be rewritten into `evendata` 2020-01-19 20:17:26 +01:00
nmlgc 98e07ec5e1 [Contributing] Don't require declarations of internal symbols in header files 2020-01-15 20:25:15 +01:00
nmlgc 0f18dbc4bd [Decompilation] [th01] Single-point drawing and retrieval
In which our typedefs mercilessly reveal ZUN's original sloppiness, and
the unncessary sign extension taking place here. Also,  unused…

Completes P0069, funded by [Anonymous] and Yanga.
2020-01-14 22:12:18 +01:00
nmlgc b0c832bdee [Decompilation] [th01] Restorable line drawing
Yes, when clipping the start and end points to the screen area, ZUN
uses an integer division to calculate the line slopes, rather than a
floating-point one. Doesn't seem like it actually causes any incorrect
lines to be drawn, though; that case is only hit in the Mima boss
fight, which draws a few lines with a bottom coordinate of 400 rather
than 399. It *might* also restore the wrong pixels at parts of the
YuugenMagan fight, causing weird flickering, but seriously, that's an
issue everywhere you look in this game.

Part of P0069, funded by [Anonymous] and Yanga.
2020-01-14 22:12:08 +01:00
nmlgc b5cef6eb69 [Maintenance] Define VRAM access macros for arbitrary bit counts
Templates would have been nicer, but as soon as you add just one
non-immediate parameter, Turbo C++ generates a useless store to a new
local variable, ruining the generated code.

Part of P0069, funded by [Anonymous] and Yanga.
2020-01-14 22:09:51 +01:00
wintiger0222 e0d0dcd51d [Maintenance] [th02] Move remaining OP.EXE variables from ASM land to C land 2020-01-14 22:09:01 +01:00
wintiger0222 4d13d7f7e9 [Decompilation] [th01] graph_printf_fx 2020-01-14 22:08:44 +01:00
nmlgc 2ac00d47bf [Decompilation] [th01] Box and rectangle drawing
Completes P0068, funded by Yanga.
2020-01-14 22:06:58 +01:00
nmlgc a6d292a62c [Decompilation] [th01] graph_putsa_fx
TH01's (original) version also replicates the PC-98 text RAM's reverse
and underline attributes. Which was removed in later games,
interestingly and inconsistently enough.

Part of P0068, funded by Yanga.
2020-01-14 22:04:12 +01:00
nmlgc 4340b5d6ae [Maintenance] [th01/th02] Split graph_putsa_fx() into its shared parts
I did consider not doing this, because "well, can't anyone who's
*actually* interested just diff the TH01 and TH02 implementations to
figure out the differences themselves", but that duplication ended up
feeling too filthy after all.

And hey, it's a nice excuse to update TH02's version to current naming
standards! 😛

Part of P0068, funded by Yanga.
2020-01-14 22:03:00 +01:00
nmlgc 4372b90ed0 [Maintenance] [th01] Fix the function name format of graph_putsa_fx
Part of P0068, funded by Yanga.
2020-01-14 22:02:10 +01:00