Commit Graph

840 Commits

Author SHA1 Message Date
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
nmlgc add988f203 [Position independence] [th01_reiiden_2.inc] Main color palette references
Not that I'm much better at this in 2020! -.-

Part of P0068, funded by Yanga.
2020-01-14 22:01:33 +01:00
nmlgc aac5bec3bd [Position independence] [th01_reiiden_2.inc] Sine and cosine table references
Yup… missed them back in cae1be46, because I forgot about REIIDEN.EXE
using two files.

Part of P0068, funded by Yanga.
2020-01-14 22:00:49 +01:00
nmlgc d66416afb2 [Position independence] [th01] Restorable line and box drawing calls
Separate commit this time, because it's a lot!

Part of P0068, funded by Yanga.
2020-01-14 21:59:20 +01:00
nmlgc ebb30ce170 [Reverse-engineering] [th01] Restorable line and box drawing
Including the longest function present in more than one game among all
of PC-98 Touhou, and #23 on the list of longest functions overall,
which draws a 1-pixel line between two arbitrary pixels.

Completes P0067, funded by Splashman.
2020-01-14 21:53:00 +01:00
nmlgc 9f7dde8953 [Decompilation] [th01] Inter-page rectangle moves
Semi-unused, that is, the one use of this function doesn't actually
move the rectangle to a different position. Ironically, the non-moving
back-to-front function immediately above *is* unused…

Also, too bad that stack order is the only reason we can't use structs
to combine all plane variables into a single object.

Part of P0067, funded by Splashman.
2020-01-14 21:50:23 +01:00
nmlgc f87b0d4f9e [Maintenance] [th01] Don't #define away master.lib's graph_accesspage() macro
We will in fact have to use both the function call and the macro
version, even within the same translation unit.

Part of P0067, funded by Splashman.
2020-01-14 21:49:38 +01:00
nmlgc 6222b78514 [Reverse-engineering] [th01] Current back page
Previously sloppily mis-RE'd as "some page variable, idk", back in
2015…
Now also with a page number typedef. And yeah, restricting bool to C++
has now proven to be stupid after all.

Part of P0067, funded by Splashman.
2020-01-14 21:48:40 +01:00
nmlgc 22ebc48eea [Decompilation] [th01] Blocking palette fade-ins from a custom start color
 Unused…

Part of P0067, funded by Splashman.
2020-01-14 21:47:17 +01:00
nmlgc e55a48b700 [Decompilation] [th01] master.lib resident palette function reimplementations
Which store colors as GRB, as suggested by the structure's ID string.
Even master.lib's own functions add an additional XCHG AH, AL
instruction to get colors into and out of this format. MASTER.MAN
suggests that it's some sort of standard on PC-98. It does match the
order of ths hardware's palette register ports, after all.
(0AAh = green, 0ACh = red, 0AEh = blue)

Now we also know why __seg* wasn't used more commonly, as lamented in
c8e8e98. Turbo C++ simply doesn't support a lot of arithmetic on
segment pointers.

And then that undecompilable far call to a function within the same
segment, but inside a different translation unit…
Also, thanks again to Egor for the SCOPY@ hack that debuted in 0460072.
Would have probably struggled with this a lot more without that.

And *then* you realize that TH01 effectively doesn't even use the
resident palette. 😐

And yes, we're procrastinating the whole issue of potentially using
a single translation unit for all three binaries by using a common
segment name, because it *really* isn't that easy.

Completes P0066, funded by Keyblade Wiedling Neko and Splashman.
2020-01-05 20:23:27 +01:00
nmlgc 6a274436db [Reverse-engineering] [th01] Basic hardware palette functions
Part of P0066, funded by Keyblade Wiedling Neko and Splashman.
2020-01-05 19:08:31 +01:00
nmlgc a3bba96a26 [Reverse-engineering] [th01] Main color palette
Part of P0066, funded by Keyblade Wiedling Neko and Splashman.
2020-01-05 19:07:48 +01:00
nmlgc 0e19e52572 [Maintenance] Templatize RGB and palette types for 4- and 8-bit components
Right, PC-98 hardware only supports 4 bits per RGB component, for a
total of 4,096 possible colors. The 8-bit RGB color values we've been
seeing throughout the later games are a master.lib extension, to allow
for more toning precision. Which TH01, with all its NIH syndrome,
doesn't use.

And yup, that means templates in the most basic header files… Since
that would have meant renaming *everything* to compile as C++, I simply
made these types exclusive to C++ code, thcrap style.

Part of P0066, funded by Keyblade Wiedling Neko and Splashman.
2020-01-05 19:06:32 +01:00
nmlgc 042b7802bf [Reverse-engineering] [th04/th05] Resident structure
And yes, you can get it in your own tool by simply #including
th04/th04.hpp or th05/th05.hpp.

Completes P0065, funded by Touhou Patch Center.
2020-01-03 21:43:43 +01:00
nmlgc c3a9816e60 [Maintenance] [th04/th05] Declare a little-endian BCD score type
Only in C land though; doing the same in ASM land actually makes digit
accesses harder to read.

Part of P0065, funded by Touhou Patch Center.
2020-01-03 21:33:30 +01:00
nmlgc 23ea2d4bee [Reverse-engineering] [th04/th05] Item collection counters
Naming hell: Storing one and the same amount in two different variables
which are used in three places

Part of P0065, funded by Touhou Patch Center.
2020-01-03 21:31:25 +01:00
nmlgc b5d56e5df2 [Reverse-engineering] [th03/th04/th05] Frame counters
Of which there are quite a lot!

Part of P0065, funded by Touhou Patch Center.
2020-01-03 21:30:02 +01:00
nmlgc 658c0291d3 [Reverse-engineering] [th04/th05] Graze counter
Part of P0065, funded by Touhou Patch Center.
2020-01-03 21:29:27 +01:00
nmlgc 5a7fb6879f [Maintenance] Use the same resident structure pointer name for every game
The TH04/TH05 BGM/SE mode setup is a good example for code where
different structure field offsets will vanish completely upon reverse-
engineering. If we continued to use the per-game ID string as the
variable name, we'd only have another game-specific "difference" there.

Part of P0065, funded by Touhou Patch Center.
2020-01-03 21:26:10 +01:00
nmlgc 9faa29abbe [Position independence] [th04/th05] Final false positives in OP.EXE
And now, the website gets it as well.

Completes P0064, funded by Touhou Patch Center.
2019-12-29 21:15:44 +01:00
nmlgc 9e8fa66a7a [Reverse-engineering] [th04/th05] Stage display in the High Score menu
Part of P0064, funded by Touhou Patch Center.
2019-12-29 21:15:44 +01:00