Commit Graph

236 Commits

Author SHA1 Message Date
nmlgc 40b8325cc3 [Maintenance] [th01] Move MDRV2 files to a separate `snd/` directory
Consistency… even though we won't have more of those in this game.

Part of P0098, funded by Yanga.
2020-06-13 21:15:30 +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 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 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 c0b44ecaec [Position independence] Remaining references to _ctype
Part of P0087, funded by -Tom-.
2020-04-15 21:34:20 +02:00
nmlgc 7698f5da6d [Maintenance] Compress unknown BSS regions using byte arrays
Also something that any future ReC project should be doing right at the
start. Finally, it made sense to do it here as well, because…

Part of P0084, funded by Yanga.
2020-03-22 10:16:09 +01:00
nmlgc 1cc9cefa26 [Decompilation] [th01] PTN-sized page 0→1 copies
Final shared function in TH01's OP.EXE.

Part of P0084, funded by Yanga.
2020-03-22 09:59:24 +01:00
nmlgc dfac2f2fd4 [Position independence] [th01] EGC-powered page 1→0 region copy calls
12.4 fixed-point subpixels, in TH01?

Completes P0083, funded by Yanga.
2020-03-18 20:33:59 +01:00
nmlgc 9e676ce3ef [Decompilation] [th01] .PTN snap functions
Which repurpose the .PTN image slots to store the background of
frequently updated VRAM sections, like all the numbers in the HUD.
Future games would simply use the text RAM and gaiji for numbers. Which
would have worked just fine for TH01 as well (especially since all the
functions we've seen so far are aligned to the 8-pixel byte grid), but
it looks as if ZUN simply wasn't aware of gaiji during the development
of TH01.

Part of P0083, funded by Yanga.
2020-03-18 20:33:58 +01:00
nmlgc a184413f27 [Decompilation] [th01] .PTN file loading and non-transparent display
What is this, error checking in a ZUN game?! And surprisingly good code
for deriving the alpha plane?!

Part of P0083, funded by Yanga.
2020-03-18 20:33:58 +01:00
nmlgc d79f4c1171 [Maintenance] [th01] Correctly declare the packfile functions in C land
Mangled C++ function names would *not* have been a mistake if I hadn't
made the other mistake of restricting parts of the code to C…

Part of P0083, funded by Yanga.
2020-03-18 20:33:53 +01:00
nmlgc 2546c5dfcb [Reverse-engineering] [th01] .PTN slot structure
Part of P0083, funded by Yanga.
2020-03-18 20:09:57 +01:00
nmlgc f6cbff0bf9 [Decompilation] [th01] .GRP file loading and display
All the weird double returns in FUUIN.EXE just magically appear with
-O-! 😮

And yeah, it's a bowl of global state spaghetti once again. 🍝 Named
the functions in a way that would make sense to a user of the API, who
should be aware of typical side effects, like, y'know, a changed
hardware palette… That's how you end up with the supposed "main"
function getting a "_palette_show" suffix.

Completes P0082, funded by Ember2528.
2020-03-13 19:48:38 +01:00
nmlgc 76634342f1 [Reverse-engineering] [th01] Global .GRP and .PTN variables
Since we not only have the .PTN sub-image count array in the middle of
all those .GRP flags, but the .PTN loading code also reusing the
palette set flag…

Part of P0082, funded by Ember2528.
2020-03-13 19:14:45 +01:00
nmlgc 63ed22ba67 [Reverse-engineering] [th01] .GRP palette
Part of P0082, funded by Ember2528.
2020-03-13 19:09:24 +01:00
nmlgc fd6a8bae81 [Decompilation] [th01] .GRZ file loading and display
Yet another run-length encoded graphics format, this one being
exclusively used to wastefully store Konngara's sword slash and kuji-in
kill "animation".

But for once, the terrible code generated by inline functions with
non-literal parameters perfectly matches what ZUN wrote here.

Part of P0081, funded by Ember2528.
2020-03-07 21:43:00 +01:00
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 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 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
wintiger0222 4d13d7f7e9 [Decompilation] [th01] graph_printf_fx 2020-01-14 22:08:44 +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 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 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 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 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 7d329202e7 [Position independence] graph_putsa_fx() calls
Waiting with the `fx` parameter in TH01's calls for the decompilation
of this game's version of this function…

Part of P0062, funded by Touhou Patch Center.
2019-12-22 15:38:31 +01:00
wintiger0222 67ab2f4a41 [Naming] [th01] Game init and exit functions 2019-12-17 23:27:01 +01:00
wintiger0222 c140281ba7 [Naming] [th01] graph_putsa_fx 2019-12-17 23:26:58 +01:00
wintiger0222 9173833a8d [Reverse-engineering] [th01] grcg_setcolor() C reimplementations 2019-12-17 23:26:57 +01:00
wintiger0222 01de2900dd [Decompilation] [th01] frame_delay
Closes #7.
2019-11-18 21:29:43 +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
nmlgc f07089017f [Maintenance] Rename the extension of game-specific ASM includes to .inc
Rule of thumb going forward: Everything that emits data is .asm,
everything that doesn't is .inc.
(Let's hope that th01_reiiden_2.inc won't exist for that much longer!)

Part of P0032, funded by zorg.
2019-09-21 13:03:56 +02:00
nmlgc 35ef90f4d1 [Reduction] Page flipping
Funded by -Tom-.
2018-12-30 00:16:18 +01:00
nmlgc 6a6ce47c56 [Reduction] EGC-powered VRAM region copies
Funded by -Tom-.
2018-12-29 17:03:26 +01:00