Commit Graph

43 Commits

Author SHA1 Message Date
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 df6b636053 [Decompilation] Add an inline function for VRAM offset calculation
Which actually does inline… in C++, because Turbo C++ doesn't support
the `inline` keyword in C mode. So much for the superiority of that
language, even in 1994…

Part of P0083, funded by Yanga.
2020-03-18 20:11:18 +01:00
nmlgc 8adbeb76b6 [Decompilation] [th01] .GRP palette fades
It's optimization barrier time again \o/

Part of P0082, funded by Ember2528.
2020-03-13 19:14:32 +01:00
nmlgc 74269c3834 [Reverse-engineering] [th01] FUUIN.EXE frame delay
Turns out that the .GRP file functions are, of course, also present in
FUUIN.EXE… but use different palette fade functions there? This is the
first function in the way.

Part of P0082, funded by Ember2528.
2020-03-13 19:06:21 +01:00
nmlgc 54e5bf39fc [Maintenance] Use `dots` for 1bpp lines, and `planar` for B/R/G/E dot structs
I tried `brge` for the latter, but that had *the* most horrible
ergonomics, and I misspelled it as `bgre` 100% of the times I typed it
manually. Turns out that `dots` is also consistent with master.lib's
naming scheme, leaving `planar` to *actually* refer to types storing
multiple planes worth of pixels. These types are showing up more and
more, and deserve something better than their previous long-winded and
misleading name.

Part of P0081, funded by Ember2528.
2020-03-07 21:19:25 +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 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 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 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 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 59bbe313ad [Decompilation] Add separate types for 1bpp planar pixel lines 2019-12-17 23:26:59 +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
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
nmlgc 41622254a8 [Reverse-engineering] EGC register writes
Funded by zorg.
2018-12-25 23:45:24 +01:00
nmlgc 43001161e3 [Maintenance] Fix any whitespace issues in our own code 2015-09-07 15:44:48 +02:00
nmlgc 14e69ceb6d [C decompilation] [th01] VSync interrupt handler
Time to get back into this.
2015-09-05 22:33:07 +02:00
nmlgc 92979e8f31 [C decompilation] [th02] Code segment #2 of all three executables
Only one code segment left in both OP and FUUIN! its-happening.gif

Yeah, that commit is way larger than I'm comfortable with, but none of these
functions is particularly large or difficult to decompile (with the exception
of graph_putsa_fx(), which I actually did weeks ago), and OP and MAIN have
their own unique functions in between the shared ones, so…
2015-03-14 23:25:50 +01:00
nmlgc 519e24c459 Rename the *_copy_region_* functions to *_copy_rect_*
TH01 copies a lot of different shapes from plane 1 to 0, so "region" feels
awfully unspecific.
2015-03-10 14:18:28 +01:00
nmlgc d058666929 [C decompilation] [th02/maine] Rotating rectangle animation
Small detour into MAINE.EXE because it has all the juicy algorithms that will
explain the remaining unknown members of the highscore data structure, and
there's this one code segment here we need to get out of the way first.
2015-02-28 22:37:40 +01:00
nmlgc 2f1b287f3d [C decompilation] [th01] VRAM region copy via EGC
The same function appears unused in TH02's MAINE.EXE. Separate commit because
this was painful enough and we can link the C version into FUUIN.EXE right
now.
2015-02-27 23:11:47 +01:00
nmlgc a7235304ed Make the VRAM plane constants available to C 2015-02-24 22:16:31 +01:00
nmlgc 07519a7238 [Reverse-engineering] 32-bit VRAM plane pointers
I've looked at every openly available piece of PC-98 documentation, and there
don't seem to be any official names for the individual planes. The closest
thing I could find was the description at

	http://island.geocities.jp/cklouch/column/pc98bas/pc98disphw2.htm

explaining that they represent the blue, red, green, and brightness component
when using the default PC-98 palette. However, these planes correspond to
nothing else but the 4 individual bits of the final index into the color
palette, and you can assign any color to every single palette slot. Therefore,
it's merely a convention that your own palettes don't have to follow (and in
Touhou, they don't).

Nevertheless, there doesn't seem to be an alternative, and the Neko Project II
source code uses the same B/R/G/E convention, so I'll go with that as well.
2015-02-10 23:43:34 +01:00