Commit Graph

251 Commits

Author SHA1 Message Date
nmlgc 3a41604314 [Decompilation] [th04/th05] Text popups
The bullet update function really needs this one declared in C land to
link without a fixup overflow? Guess we'll have another technical debt
push before then…

Part of P0148, funded by [Anonymous].
2021-07-20 23:35:46 +02:00
nmlgc ebbb5b8255 [Maintenance] Move tile-related files to their own subdirectory
The next commit will make clear that tile functionality is not a subset
of the non-boss stage code.

Part of P0147, funded by -Tom- and Ember2528.
2021-06-20 19:37:20 +02:00
nmlgc 8426f3e13f [Maintenance] Make the playfield fraction functions available to ≥TH02
Part of P0146, funded by -Tom- and Ember2528.
2021-06-09 23:10:01 +02:00
nmlgc 3e2104a164 [Maintenance] [th02] Move the packfile name constant to th02/shiftjis/
Now you can grep for it¹!

¹ Editor that's actually smart enough to not only correctly detect
  Shift-JIS during grepping, but also match the characters in a search
  regardless of file encoding, sold separately

Part of P0141, funded by [Anonymous] and rosenrose.
2021-05-27 19:35:02 +02:00
nmlgc 241b61e808 [Maintenance] Distinguish between Shift-JIS and gaiji strings
The main point of the previous strings/ subdirectory was to bundle all
hardcoded strings for translators. And sure, *technically*, gaiji
strings are *both* strings *and* something you might want to translate.
But mainly, they're sprites with an attached enum, and their own
directory. Changes to the enum quickly tend to involve changes to the
strings that use these values, so it makes sense to keep both in the
same directory.

Especially since 82% of the previous strings/ directories consisted of
such gaiji strings.

That leaves the strings/ directory rather empty and nondescript though.
Recently though, I've been wanting to generally move all Shift-JIS text
to this directory. While that wouldn't *solve* the typical "text editor
accidentally a file upon save, due to wrongly detected encoding" issue,
it's at least a mitigation: If all Shift-JIS strings are in files that
contain nothing *but* Shift-JIS strings, a wrongly detected encoding
becomes immediately noticeable.

For that job, strings/ can have a more descriptive name though. Hence,
shiftjis/.

Part of P0141, funded by [Anonymous] and rosenrose.
2021-05-27 19:10:26 +02:00
nmlgc 68d9419e8e [Maintenance] [th02] Remove ranks_center[data].asm
Part of P0141, funded by [Anonymous] and rosenrose.
2021-05-27 19:08:57 +02:00
nmlgc d9858113d8 [Decompilation] [th04] snd_load()
Last one! Done with the SHARED segment for the forseeable future! 🎉

Sure, not the best C++ code either, but still by far the sanest
implementation of this function in any of the 4 games.

Completes P0139, funded by [Anonymous].
2021-05-12 14:31:03 +02:00
nmlgc cd96b039fa [Maintenance] Use a dedicated enum for snd_load()'s function parameter
It's not a kaja_func_t if it's shifted left by 8 bits. Why is it
shifted left by 8 bits to begin with, though? Why not just pass a
kaja_func_t, and assign it to AH? Arrrrgh.

Part of P0139, funded by [Anonymous].
2021-05-12 14:31:02 +02:00
nmlgc 46a1674250 [Reverse-engineering] [th02/th03/th04/th05] snd_load() buffer size
Hardcoding these *might* have been acceptable if the numbers actually
matched the sizes defined in GAME.BAT, but they don't. With PMD's
AH=22h function, there's really no excuse though.
About time I looked into this, and expressed that constant as an inline
function that can easily be replaced with a proper implementation.

Part of P0139, funded by [Anonymous].
2021-05-12 14:31:00 +02:00
nmlgc 62e0167e20 [Translation unit catch-up] [th03/th04/th05] snd_delay_until_measure(), game_exit_to_dos()
Segment alignment issues once again… but that completes the SHARED
segments of all TH03 and TH05 binaries, for now!

Part of P0139, funded by [Anonymous].
2021-05-11 18:48:00 +02:00
nmlgc 14cb1d3665 [Maintenance] Document relevant return values of PMD's AH=09h function
I'll leave a comprehensive, fully documented enum to interested
contributors, since that would involve research into basically the
entire history of the PC-9800 series, and even the clearly out-of-scope
PC-88VA. After all, PC-98 Touhou only needs to distinguish "OPN- /
PC-9801-26K-compatible sound sources handled by PMD.COM" from
"everything else", since all other PMD varieties are OPNA- /
PC-9801-86-compatible.

Part of P0139, funded by [Anonymous].
2021-05-11 18:47:58 +02:00
nmlgc 7761f4e804 [Decompilation] [th04] snd_kaja_interrupt()
4 games, 4 different versions of this function. Interestingly,
moving the game-specific differences to inline functions makes it
obvious that this function was only intended for BGM, not sound
effects.

Part of P0139, funded by [Anonymous].
2021-05-11 18:47:57 +02:00
nmlgc 4c0e76ab89 [Decompilation] [th04/th05] snd_mmd_resident()
Part of P0139, funded by [Anonymous].
2021-05-11 18:47:57 +02:00
nmlgc acd29854c7 [Decompilation] KAJA driver ISR magic check
Down to one inline ASM instruction for these.

Part of P0139, funded by [Anonymous].
2021-05-11 18:47:55 +02:00
nmlgc 864e8643ab [Decompilation] [th04] .MPN: Load function
Basically just a copy of the TH02 one, adjusted to work with multiple
slots.

Completes P0138, funded by [Anonymous] and Blue Bolt.
2021-04-22 19:27:48 +02:00
nmlgc b1cf7ee021 [Maintenance] [th02] .MPN: Update existing decompilations to current standards
Part of P0138, funded by [Anonymous] and Blue Bolt.
2021-04-22 19:25:01 +02:00
nmlgc f635948480 [Naming] .MPN: Rename mptn_* to mpn_*
We've been using the three-letter extension names for everything else
that isn't .DAT, so it's more consistent to do the same for .MPN,
however particularly nice and readable its FOURCC may be. 8.3 filenames
also really appreciate that they'll have to accommodate one fewer
letter.

Part of P0138, funded by [Anonymous] and Blue Bolt.
2021-04-22 19:16:18 +02:00
nmlgc 9739f69729 [Maintenance] Add a 1bpp rectangle template, for custom per-row types
This gets rid of a couple of per-entity sprite bitplane types, makes
sprite declarations easier to read by putting width and height next to
each other… and points out a number of array dimension mistakes -.-
Even in places where we can't use it.

Part of P0138, funded by [Anonymous] and Blue Bolt.
2021-04-21 18:01:57 +02:00
nmlgc e1d5bdafed [Maintenance] master.hpp: Type-safe hmem_allocbyte() and hmem_free() wrappers
Sure, we can't use them everywhere, but it's really nice to get rid of
that casting madness – and any explicit references to x86 memory
segmentation – wherever we can.

Part of P0138, funded by [Anonymous] and Blue Bolt.
2021-04-21 17:50:12 +02:00
nmlgc 78b958f111 [Separate translation units] [th02] key_delay()
Part of P0138, funded by [Anonymous] and Blue Bolt.
2021-04-21 17:50:04 +02:00
nmlgc 04038449c1 [Translation unit catch-up] [th04] frame_delay() / .PI display and loading
Segment alignment forces us to do all of those at once… but now, we've
not only caught up with the segment split point in TH04's OP.EXE and
MAINE.EXE, but also decompiled all instances of DEFCONV functions!

Part of P0138, funded by [Anonymous] and Blue Bolt.
2021-04-21 17:44:15 +02:00
nmlgc 531b044cb9 [Separate translation units] [th01/th02/th03/th04] vram_planes_set()
Boom! Clever segment renaming allows us to link the same .OBJ into 12
binaries.
(Well, 10 for now, due to alignment issues in TH04's OP.EXE and
MAINE.EXE.)

Part of P0138, funded by [Anonymous] and Blue Bolt.
2021-04-21 17:40:11 +02:00
nmlgc 9d2cce16a2 [Translation unit catch-up] [th03] snd_determine_mode()
Wow, it's -WX, and no workaround necessary!

Part of P0138, funded by [Anonymous] and Blue Bolt.
2021-04-21 17:28:59 +02:00
nmlgc e43e3a3fbb [Translation unit catch-up] [th03] snd_pmd_resident()
Not even used in this game.

Part of P0138, funded by [Anonymous] and Blue Bolt.
2021-04-21 17:27:55 +02:00
nmlgc 1e5c677ae9 [Translation unit catch-up] [th03] snd_delay_until_volume()
Part of P0138, funded by [Anonymous] and Blue Bolt.
2021-04-21 17:26:43 +02:00
nmlgc 0e11d33520 [Translation unit catch-up] [th03] snd_load()
Exhibit B for the theory that ZUN did *not* set the default calling
convention to `pascal` for TH03.

Part of P0138, funded by [Anonymous] and Blue Bolt.
2021-04-21 16:28:29 +02:00
nmlgc 8d953dc42e [Decompilation] [th03/th04/th05] 2D direction vector construction
Hey, a disgustingly impossible "decompilation" again, for a change!

Completes P0137, funded by [Anonymous].
2021-04-04 00:02:50 +02:00
nmlgc bda7b16758 [Maintenance] Move the polar coordinate conversion functions to their own file
math/vector.hpp needs zero dependencies, this needs master.hpp.

Part of P0137, funded by [Anonymous].
2021-04-03 22:31:00 +02:00
nmlgc 6264ca743c [Translation unit catch-up] [th03/th04] game_exit()
Part of P0137, funded by [Anonymous].
2021-04-03 22:29:12 +02:00
nmlgc 2527e6ee7c [Translation unit catch-up] [th03] frame_delay()
Also requires more workarounds for TH02 so that we can share this
translation unit across the two games.

Part of P0137, funded by [Anonymous].
2021-04-03 22:15:51 +02:00
nmlgc c85f444b07 [Decompilation] [th02/th03] Sound effect playback
Second previously undecompilable translation unit, second creative
workaround for the workaround. We can't compile snd_se_play() with -WX,
as that function needs a stack frame, and it's also illegal to disable
-WX in the middle of a translation unit. But since we only need word
alignment in front of snd_se_reset() *and* that function is identical
in all 4 games, it makes sense to move it to its own translation unit.

And then you notice that the TH02/TH03 and TH04/TH05 versions of the
other two functions are basically identical. The small differences can
easily be moved out to inline functions, leaving us with a single
implementation file for all 4 games. Nice!

Part of P0137, funded by [Anonymous].
2021-04-03 22:11:45 +02:00
nmlgc 8de326792c [Decompilation] [th02] snd_mmd_resident()
Now actually decompilable with the discovery of -WX… even though it
now requires additional workarounds for the drawbacks of the -WX
workaround.

Part of P0137, funded by [Anonymous].
2021-04-03 22:10:41 +02:00
nmlgc 1244bd74e7 [Maintenance] Prefer the -zC and -zP options over `#pragma codeseg`
Might look uglier, but has the advantage of not generating an empty
segment with the default name… *and* the default padding, which will
really come in handy with the following breakthrough.

Part of P0137, funded by [Anonymous].
2021-04-03 20:12:09 +02:00
nmlgc 8bcf5d7b84 [Regression] Explicitly request 16-bit default segments when using .MODEL
Whoops, turns out that the build has been broken on TASM32 version 5.3
(the one in the DevKit) ever since 7897bf1. In contrast to version 5.0
(which I use for my development), 5.3 actually defines 32-bit segments
if you specify a .386 CPU before using .MODEL.

That might have been the reason for the .286 workaround all along?
Turns out there's the USE16 modifier, which makes this much more
explicit than switching CPUs.
2021-03-29 22:39:11 +02:00
nmlgc 07bfcf2841 [Separate translation units] [th02] input_sense()
Finishing this push with some semi-maintenance… and yet another `inline`
function replacing a `#define` ASM macro with fully idiomatic C++ code.

Completes P0136, funded by [Anonymous].
2021-03-20 02:36:43 +01:00
nmlgc af13720486 [Translation unit catch-up] [th03] .PI blitting
Part of P0136, funded by [Anonymous].
2021-03-20 02:36:43 +01:00
nmlgc 0d82f113e9 [Translation unit catch-up] [th04] game_init_op(), game_init_main()
Padding byte-induced undecompilability of cdg_put_noalpha_8() avoided 👌

Part of P0136, funded by [Anonymous].
2021-03-20 02:36:41 +01:00
nmlgc 46359e643e [Translation unit catch-up] [th05] game_exit()
Part of P0136, funded by [Anonymous].
2021-03-20 02:36:32 +01:00
nmlgc 1ad64dc514 [Translation unit catch-up] [th03] Sound effect playback
Part of P0136, funded by [Anonymous].
2021-03-20 02:17:07 +01:00
nmlgc 0929d91e50 [Translation unit catch-up] [th03] snd_kaja_interrupt()
Part of P0136, funded by [Anonymous].
2021-03-20 02:17:05 +01:00
nmlgc d25daf7075 [Maintenance] Move the number of VRAM planes to pc98.h
Allowing us to consistently mirror the declaration in pc98.inc
without adding a planar.inc file. 😛 And points us to two more
dots8_t* arrays that should have used the Planar<> template.

Part of P0135, funded by [Anonymous].
2021-03-19 19:29:17 +01:00
nmlgc 01c92da1ac [Decompilation] [th05] snd_load()
A decompilation of ZUN-written ASM that was almost worth it, for once!
Too bad that those aren't the <string.h> intrinsics that the
Wolfenstein 3D disassembly hinted at, though.

Part of P0135, funded by [Anonymous].
2021-03-19 19:22:57 +01:00
nmlgc 0d66e748d1 [Maintenance] Replace wrong `cPtrSize` usage with the ARG directive
Turns out that ARG RETURNS is only really necessary in DEFCONV
functions, which are explicitly declared to use either the C or PASCAL
calling convention. In functions without such a declaration, ARG by
itself works just fine, and won't emit any instructions on its own.
The parameter lists for PASCAL functions still have to be reversed in
that case, though… oh well, let's just comment these cases to hopefully
reduce the confusion.

Part of P0134, funded by [Anonymous].
2021-02-20 23:50:01 +01:00
nmlgc 1c5ed4b06e [Maintenance] Copy <dos.h>'s 16-bit x86 Real Mode declarations to a new file
DOS is not the same thing as the underlying CPU, after all. A separate
file not only indicates to future port authors which parts of the code
are x86-specific, but it also speeds up build times…

… in theory, because removing 677 lines from 49 files each doesn't seem
to speed up the build as much as I had hoped? But apparently my whole
system mysteriously got faster in the meantime, and I was getting 22-23
seconds for the entire repo even before this commit. Good enough.

Part of P0134, funded by [Anonymous].
2021-02-20 23:49:45 +01:00
nmlgc 59fb8753bc [Maintenance] Only use the `far` keyword to declare intent
Part of P0134, funded by [Anonymous].
2021-02-20 15:47:30 +01:00
nmlgc 604b2c83ac [Maintenance] Avoid MK_FP() where possible
It's not necessary for assigning `__seg` pointers to `far` ones, which
might even remove the <dos.h> dependency in some translation units.

Part of P0134, funded by [Anonymous].
2021-02-20 15:47:00 +01:00
nmlgc 7a44adf8d0 [Maintenance] Use the C++ resdata_*() wrappers in all ZUN.COM sub-binaries
Getting us completely macro-free there… even though it did require a
separate version of those functions if the ID is a pointer.

Part of P0134, funded by [Anonymous].
2021-02-20 15:46:48 +01:00
nmlgc 1d5db7155a [Separate translation units] [th02/th03/th05] game_init_op()
Completes P0133, funded by [Anonymous].
2021-01-31 16:53:59 +01:00
nmlgc e8588b1b0a [Separate translation units] [th02] game_exit()
Part of P0133, funded by [Anonymous].
2021-01-31 16:53:55 +01:00
nmlgc 84d4914a3b [Separate translation units] [th02] snd_mmd_resident() (undecompilable)
Reason: Wants to be word-aligned, and the previous version in OP.EXE,
game_exit(), is not, despite having an even length :(
Oh well, at least I'm confident enough about it by now to document it.
And out of all decompilations to be thrown away, this is a pretty
dispensable one.

Part of P0133, funded by [Anonymous].
2021-01-31 15:21:11 +01:00