Commit Graph

1330 Commits

Author SHA1 Message Date
nmlgc 6d69ea8152 [Maintenance] Decide on `_masked` instead of `_mask` for blitting functions
Because there are only three functions that didn't already follow this
naming scheme.

(Maintenance mode commit)
2020-12-02 00:10:48 +01:00
nmlgc f4c2e45671 [Decompilation] [th01] Stage objects: Initialization
Lol @ Konngara decompilation being blocked by this giant card-flipping
function that took 2 pushes to understand, only for it to start with

	if((stage % 5) == 4) {
		return;
	}

…

Completes P0129, funded by Yanga.
2020-12-01 00:34:22 +01:00
nmlgc dd74e8a3cd [Reverse-engineering] [th01] Stage objects: Sprite IDs
Part of P0129, funded by Yanga.
2020-12-01 00:34:22 +01:00
nmlgc 35b4461b22 [Decompilation] [th01] Stage objects: VRAM page 0 → 1 copies
This is where the code generation actually confirms the SoA layout of
the global obstacle structure, rather than it being distinct pointers.

Part of P0129, funded by Yanga.
2020-12-01 00:34:21 +01:00
nmlgc 4b24c13d3d [Decompilation] [th01] Stage objects: Obstacle initialization
Part of P0129, funded by Yanga.
2020-12-01 00:34:21 +01:00
nmlgc 9f9d27554b [Decompilation] [th01] Stage objects: STAGE?.DAT loading
Final set of file loading calls in TH01!

Part of P0129, funded by Yanga.
2020-12-01 00:34:20 +01:00
nmlgc dde36f7f89 [Decompilation] [th01] Stage objects: Background snapping
Completes P0128, funded by Yanga.
2020-12-01 00:34:20 +01:00
nmlgc 73f62a5ba2 [Decompilation] [th01] Stage objects: Background allocation and blitting
Continuing the good error handling from the .PTN functions they're
based on… if only its sole caller actually cared.

Also: A sort-of limit of 102 objects per stage, just because someone
didn't use huge pointers where they would have been necessary…
:tannedcirno:

Part of P0128, funded by Yanga.
2020-12-01 00:34:18 +01:00
nmlgc 27b3f29a0a [Reverse-engineering] [th01] Stage objects: Card flip scores
Case in point: This structure member, which is located after all the
obstacle members. Sure, it'll look weird to see this one initialized by
a class method, but it'll be much weirder to somehow group both cards
and obstacles into one class.

Part of P0128, funded by Yanga.
2020-11-29 18:03:39 +01:00
nmlgc 7df4e0517b [Reverse-engineering] [th01] Stage objects: Obstacle class
And another one for all the obstacle types we saw earlier. The original
game probably combined all SoA pointers for both cards and obstacles
into a single "stage object". But that'll get way too unwieldy in the
functions later, given that those aren't even methods, and simply
reference one global variable. `stageobjs.obstacles.member`… yeah, no.

Part of P0128, funded by Yanga.
2020-11-29 17:59:03 +01:00
nmlgc 8e43f48b69 [Reverse-engineering] [th01] Stage objects: Card class
Sure, a SoA layout might actually be genius and what you should be
doing most of the time on modern systems, but you still wouldn't
allocate every member separately.

Part of P0128, funded by Yanga.
2020-11-29 17:59:01 +01:00
nmlgc 0ea53cf841 [Reverse-engineering] [th01] Stage objects: Obstacle types
An enum to distinguish between bumpers, turrets, portals, bumper bars…
and cards that have to be flipped more than once?!

Part of P0128, funded by Yanga.
2020-11-29 17:01:14 +01:00
nmlgc 3fc43a3dba [Maintenance] [th01] Start a new header file for stage objects
As we're going to see, some of these share some of the allocations.

Part of P0128, funded by Yanga.
2020-11-29 16:53:58 +01:00
nmlgc dc65b59dcc [Decompilation] [th05] frame_delay()
Finishing this push with another highly questionable one… Let's hope
that the port developers will certainly appreciate that they just have
to remove the weirdness here, and not mess with defining entirely new
functions in C land.

Completes P0127, funded by [Anonymous].
2020-11-16 20:01:36 +01:00
nmlgc 7897bf166f [Separate translation units] [th04/th05] .CDG: Loading and freeing
Undecompilable again. The loading functions have these *_noalpha()
variants that simply set a global variable and fall through to the
regular functions, while cdg_free() has its first `PUSH DI` instruction
after the first expression we'd be decompiling. cdg_free_all() *could*
be decompiled… but would also require _FLAGS trickery, and it's simply
not worth starting a translation unit for one such small function.

Part of P0127, funded by [Anonymous].
2020-11-16 20:01:35 +01:00
nmlgc 00f177e196 [Maintenance] [th03] Remove the input mode and delay function disassembly
MAIN.EXE now also caught back up with the decompilation.

Part of P0127, funded by [Anonymous].
2020-11-16 20:01:35 +01:00
nmlgc 8835d59eda [Build] [th03] Keep hflip_lut_generate() in ASM due to alignment issues
Nooooo, gotta throw away that decompilation for the stupidest of
reasons :( Turns out that a function may also be "undecompilable" if
the original code layout places it at a word-aligned address, but the
last byte of the previous function in just one of the original binaries
(TH03's MAIN.EXE, in this case) also lies at a word-aligned address.
There's simply no way to enforce per-function word alignment in Turbo
C++ alone. You *could* fake it with `#pragma codestring`, but of course
that won't work for functions that are part of the SHARED segment, and
where the alignment previously would have been correct. Conditionally
emitting that codestring would work, but then we'd also have to compile
that translation unit at least twice.

Now, I could have created a dummy .ASM file that just contains a single
zero-length but word-aligned SHARED segment, which could be placed
anywhere on the link command line where word alignment is needed… but
the decompilation of this function was a mess anyway, and probably
helped nobody.

Part of P0127, funded by [Anonymous].
2020-11-16 20:01:34 +01:00
nmlgc f7931167fc [Decompilation] [th03] .MRS: Slot loading function
Still too micro-optimized to be decompilable into something sane…
Anyway, .MRS done.

Part of P0127, funded by [Anonymous].
2020-11-16 20:01:34 +01:00
nmlgc 1fe9863e47 [Decompilation] [th03] .MRS: Slot freeing function
How can you mess up *a freeing function* that badly?! In your third
game?!

Part of P0127, funded by [Anonymous].
2020-11-16 20:01:33 +01:00
nmlgc 00e65f4c6b [Decompilation] [th03] .MRS: Alpha-tested byte-aligned blitting
And since inlining even removes longer if-else chains if they branch
depending on a literal constant, we can use a regular parameter to
select either MOV or OR in our _FS and _GS poke() template functions,
without needing to duplicate them!

Part of P0127, funded by [Anonymous].
2020-11-16 20:01:32 +01:00
nmlgc 8b0165738a [Decompilation] [th03] .MRS: Byte-aligned, opaque blitting
Containing not one, but two decompilation innovations, one of which
works around a compiler bug using C++ template functions…

Completes P0126, funded by [Anonymous] and Blue Bolt.
2020-11-16 20:01:32 +01:00
nmlgc 5965930bd0 [Decompilation] [th03] .MRS: Persistent horizontal flipping
Another function consisting almost entirely of inline ASM. Still worth
it though, if only to save us from duplicating any declarations in ASM
land.

Part of P0126, funded by [Anonymous] and Blue Bolt.
2020-11-16 20:01:31 +01:00
nmlgc 08a09aabb2 [Reverse-engineering] [th03] .MRS: Bitplane pointers
Part of P0126, funded by [Anonymous] and Blue Bolt.
2020-11-16 20:01:26 +01:00
nmlgc baac3f7682 [Decompilation] [th04/th05] EGC-powered page 1→0 rectangle blitting
Actually fairly average, as far as unreasonable decompilations are
concerned. No `goto`, at least! Another place that would benefit from
EGC raster op documentation, though.

Also, got one more padding byte in TH05's MAINE.EXE correct. 🙂

Part of P0126, funded by [Anonymous] and Blue Bolt.
2020-11-16 20:01:09 +01:00
nmlgc b504d72301 [Maintenance] Move decomp.h out of th01/hardware/egc.h
Part of P0126, funded by [Anonymous] and Blue Bolt.
2020-11-15 21:30:58 +01:00
nmlgc 74a11d667d [Maintenance] master.hpp transition: Resident data
With a type-safe wrapper template that removes the need for ID length
and structure-size-in-paragraphs macros. *And* <dos.h>!

Part of P0126, funded by [Anonymous] and Blue Bolt.
2020-11-15 21:28:55 +01:00
nmlgc 9c36df72e5 [Maintenance] [th01] Get rid of th01.h
Part of P0126, funded by [Anonymous] and Blue Bolt.
2020-11-15 21:27:41 +01:00
nmlgc aea27d2221 [Maintenance] master.hpp transition: DOS functions
Part of P0126, funded by [Anonymous] and Blue Bolt.
2020-11-15 21:23:29 +01:00
nmlgc 199f73eba4 [Maintenance] master.hpp transition: Math declarations
Part of P0126, funded by [Anonymous] and Blue Bolt.
2020-11-15 21:22:15 +01:00
nmlgc d515d67c9f [Maintenance] master.hpp transition: Optionally buffered single-file I/O
Now the fact that those can be buffered is also documented outside of
MASTER.MAN.

Part of P0126, funded by [Anonymous] and Blue Bolt.
2020-11-15 21:21:04 +01:00
nmlgc 90f1c2ca93 [Maintenance] master.hpp transition: Text RAM declarations
Part of P0126, funded by [Anonymous] and Blue Bolt.
2020-11-15 21:19:42 +01:00
nmlgc b104b3316b [Maintenance] Consistently use Borland's I/O port intrinsics
Rather than preferring either the Microsoft/Watcom `(in|out)pw?` style,
or the Borland `(in|out)portb?` style, master.lib had to introduce its
own `(OUT|IN)P[BW]` naming scheme… Insert obligatory xkcd standards
comic.

Part of P0126, funded by [Anonymous] and Blue Bolt.
2020-11-15 21:16:40 +01:00
nmlgc 6c22af7e83 [Build] [th01] Only compile shared single-file translation units a single time
Which gets rid of 13 redundant translation units. Definitely a good
start, before I figure out how to best handle the more complicated
cases.

(Maintenance mode commit)
2020-11-04 14:47:52 +01:00
nmlgc 7d83739eb8 [Build] [th01] Merge vsync_callback_clear() into vsync.c
Not really surprising why this works, and probably was how the original
code looked all along: The function is never called from anywhere, and
as long as the next function still lies on the same 16-byte paragraph,
it makes no difference whether the unused one is placed at the end of
the previous segment, or the beginning of the next.
Which means we can choose whatever leads to fewer translation units 👍

(Maintenance mode commit)
2020-11-04 14:42:37 +01:00
nmlgc 4850d6d457 [Maintenance] Rename "seg2" to "SHARED"
There's the better name, in ALLCAPS for improved grepping. TH01 is also
going to need a pseudo-binary to bundle translation units that appear
in more than one .EXE, and since "segment 2" would be wrong for that
game, it makes more sense to have one consistent name for these
pseudo-binaries in all games.

(Maintenance mode commit)
2020-11-03 17:01:26 +01:00
nmlgc f6a3246071 [Reverse-engineering] Enabling and disabling the EGC
Which involves temporarily enabling a GDC mode change bit.

Completes P0125, funded by [Anonymous].
2020-11-02 23:42:04 +01:00
nmlgc 6a8de71720 [Maintenance] master.hpp transition: EGC declarations
Part of P0125, funded by [Anonymous].
2020-11-02 23:33:09 +01:00
nmlgc e8ae29ca4e [Maintenance] Remove the old `planar(8|16|32)_t` types
All code that used them has transitioned to C++, and can use the
Planar<> template.

Part of P0125, funded by [Anonymous].
2020-11-02 23:04:54 +01:00
nmlgc deecfeb0d1 [Position independence] [th02] graph_putsa_fx() calls in MAINE.EXE
Part of P0125, funded by [Anonymous].
2020-11-02 23:00:54 +01:00
nmlgc 8eb0d33e80 [Decompilation] [th04] Character selection: Raised top/left edge background
Yup, no trick there. If the selection moves to the other character, the
original background behind the raised top and left edges has to be
blitted back to VRAM, which means that it also has to be stored
somewhere. TH04 backs up exactly the two 256×8 and 8×244 strips behind
Reimu and Marisa, requiring 2 KB of heap memory, whereas TH05 simply
gave up, and backs up the entire 640×400 screen, totalling 128 KB.

Part of P0125, funded by [Anonymous].
2020-11-02 22:43:05 +01:00
nmlgc 056b1c77c1 [Decompilation] [th04] Player character and shot type selection menu
Significantly more complex than the single menu in TH05!

Completes P0124, funded by [Anonymous] and Blue Bolt.
2020-11-02 22:41:51 +01:00
nmlgc f1c63ab3a1 [Reverse-engineering] Assign names to all graph_putsa_fx() effects
And get rid of the constraining FX() macro, with its spacing parameter
that we haven't even seen used so far.

Part of P0124, funded by [Anonymous] and Blue Bolt.
2020-11-02 22:33:50 +01:00
nmlgc 774b172028 [Maintenance] Only define pi_load_put_8_free() a single time
The change of pi_free() from a macro to a function in TH05 doesn't
require a complete redefinition.

Part of P0124, funded by [Anonymous] and Blue Bolt.
2020-11-02 22:30:39 +01:00
nmlgc 3ee848f456 [Maintenance] [th05] Use master.hpp for the character selection menu
6149 LoC with the original master.h, vs. 2524 LoC *and* additional
semantic sugar with master.hpp. Nice!

(Yes, *semantic* sugar.)

Part of P0124, funded by [Anonymous] and Blue Bolt.
2020-11-02 22:21:51 +01:00
nmlgc 30462cc64f [Maintenance] Indicate byte alignment for all .PI blitting functions
Part of P0124, funded by [Anonymous] and Blue Bolt.
2020-11-02 22:19:12 +01:00
nmlgc b674adff18 [Maintenance] master.hpp transition: Heap functions
Part of P0124, funded by [Anonymous] and Blue Bolt.
2020-11-02 22:17:48 +01:00
nmlgc 327f68a8d2 [Maintenance] Fix the names for DEFCONV functions in ASM land -.-
Part of P0124, funded by [Anonymous] and Blue Bolt.
2020-11-02 22:15:42 +01:00
nmlgc 65a12d13a8 [Maintenance] master.hpp transition: .PI declarations
Part of P0124, funded by [Anonymous] and Blue Bolt.
2020-11-02 22:09:17 +01:00
nmlgc c8fa62d0c2 [Maintenance] master.hpp transition: GRCG declarations
Part of P0124, funded by [Anonymous] and Blue Bolt.
2020-11-02 21:50:51 +01:00
nmlgc e78f73d779 [Maintenance] master.hpp transition: Graphics declarations
Part of P0124, funded by [Anonymous] and Blue Bolt.
2020-11-02 21:48:51 +01:00