Commit Graph

24 Commits

Author SHA1 Message Date
nmlgc b61e612fdf [Maintenance] #include each header's dependencies within the header itself
OK, this is the big one. We still keep using `#include` guards only
where we absolutely need to, but with each header now being valid in
isolation, this can now actually help *minimize* the length of each
translation unit's `#include` list. Turns out that after removing all
the duplicates, we only *actually* need to guard 29 headers across all
5 games.

Part of P0285, funded by [Anonymous] and iruleatgames.
2024-07-09 08:46:42 +02:00
nmlgc b44c74886e [Maintenance] EGC: Move implementation macros into a separate header
Avoids the `decomp.hpp` dependency in `th01/hardware/egc.h`.

Part of P0284, funded by [Anonymous] and Blue Bolt.
2024-07-09 08:41:54 +02:00
nmlgc 0e96a8e578 [Research] Document why TH02 and TH03 must manually pause BGM before loading
And the fact that TH04 and TH05 do it automatically. This allows us to
share the 'm' command implementation between the cutscene system and
the upcoming decompilation of TH04's dialog system… after developing
another new piece of decompilation tech 👀

Part of P0258, funded by [Anonymous] and Blue Bolt.
2023-10-31 22:33:41 +01:00
nmlgc 25ba371a34 [Decompilation] [th04/th05] Gather circles: Spawn functions
No point in prettifying this dumb copy macro if we're going to throw it
out on the future `debloated` branch anyway. Avoiding compiler warnings
by removing seemingly superfluous `if` statements is much more
important.

Part of P0245, funded by [Anonymous], Blue Bolt, Ember2528, and Yanga.
2023-07-01 05:22:23 +02:00
nmlgc 49a6834c4a [Maintenance] Move OUT for 8-bit port numbers to x86real.h
We'd like to use this optimization in the platform layer as well.
Turning it into an inline function via __emit__() also allows us to
turn a bunch of other macros into proper inline functions.

Part of P0232, funded by [Anonymous].
2023-02-28 08:08:17 +01:00
nmlgc 055cc20f79 [Platform] [x86 Real Mode] CPU flag macros
Over on the `debloated` branch, we're going to use them in our own
platform-specific code, which obviously is not decompiled from
anything.

Part of P0232, funded by [Anonymous].
2023-02-28 08:08:16 +01:00
nmlgc a503ba3095 [Maintenance] [th01] Fix temporary macros
We have, in fact, already decompiled all FPU code in PC-98 Touhou.

Part of P0230, funded by [Anonymous].
2023-02-28 08:07:53 +01:00
nmlgc bfd24c6ae3 [Decompilation] Turn the FS/GS prefix workaround into a full-on code generator
If we double down on this concept by defining all needed prefix and R/M
opcodes, the code turns out much simpler if we __emit__() even the
basic, non-broken case. And if the inlined functions directly take
the opcode bytes as parameters, we don't even need templates.

Completes P0227, funded by nrook.
2023-01-17 11:40:36 +01:00
nmlgc 990588a4ea [Research] Finally figure out relativity of near references
Biggest decompilation breakthrough of the year already? Completely
removes the need for the "set near pointer to far function" hack, and
solves quite a few upcoming issues.
The TASM manuals did have a few pages on the topic of segments and
groups, but there's absolutely nothing about it in the TCC ones beyond
the three-sentence description of `#pragma codeseg` and that completely
unhelpful "🤷" of an explanation for the `Fixup overflow` error…

Part of P0227, funded by nrook.
2023-01-16 12:05:29 +01:00
nmlgc 690b4df14b [Maintenance] Fix another bunch of accumulated typos and dead code
Part of P0216, funded by JonathKane.
2022-08-16 01:38:12 +02:00
nmlgc 60a7e44b53 [Maintenance] Introduce proper Shift-JIS and JIS X 0208 types
Much more semantic than that twobyte_t abomination.

Part of P0212, funded by GhostRiderCog, Lmocinemod, and LeyDud.
2022-08-11 15:53:13 +02:00
nmlgc a10fe95b31 [Maintenance] Fix comment↔code associations
• Comments that describe all lines of code until a blank one are placed
  into the lines immediately above
• Comments that describe an entire demarcated block are placed
  immediately below the dash row at the top
• In any case, there should be a blank line after the top comment of
  a demarcated block, to keep IntelliSense-style systems from applying
  the block comment to the first actual line of code…
• …but there shouldn't be one before the dash row at the bottom, where
  it'd be redundant.

Part of P0207, funded by GhostPhanom.
2022-08-08 20:10:53 +02:00
nmlgc 0c682b5bc0 [Maintenance] Declare the optimization_barrier() a single time
And put that single instance into the compiler optimization workaround
section of `decomp.hpp`.

Part of P0204, funded by [Anonymous].
2022-07-10 13:45:18 +02:00
nmlgc bca1b7d38a [Maintenance] Add a `nullptr` polyfill to platform.h
Which allows us to remove <stddef.h> from translation units that just
needed it for `NULL`.

Part of P0203, funded by [Anonymous] and GhostRiderCog.
2022-07-10 13:02:51 +02:00
nmlgc 54fe83513b [Maintenance] Remove the intended type from the -Z -3 inhibition macro
Nobody cares about preserving perfect semantics across a macro whose
only job is to worsen code generation on one specific compiler. And
even aside from semantics, signedness would be the only difference that
types would make, and parameter passing couldn't care less about it.

Part of P0201, funded by Ember2528 and Yanga.
2022-06-24 23:25:08 +02:00
nmlgc af7dd08626 [Decompilation] [th01] Elis: Pattern 1/13
The one where Elis fires 11 (yes, 11) evenly spaced lasers from her
left eye (?) across the whole playfield, from either the left or right
edge to the other one. First pattern you see in the fight.

Part of P0193, funded by Ember2528.
2022-05-31 22:55:33 +02:00
nmlgc 70b30221da [Maintenance] Move `nearfunc_t_near* = farfunc_t_far;` workaround to decomp.hpp
Shinki will also require it. At least there's hope that we can get rid
of it close to the completion of TH04 and TH05.

Part of P0191, funded by nrook.
2022-05-01 00:22:03 +02:00
nmlgc 5bca6bed0f [Decompilation] [th04/th05] Gather circles: Update function
Featuring a stupid variant of Turbo C++'s __memcpy__() intrinsic that
does the exact same thing, but just with reordered instructions. What a
waste of time.

Part of P0189, funded by Arandui and Lmocinemod.
2022-04-16 23:53:47 +02:00
nmlgc a2358bef47 [Maintenance] Remove `extern "C"` from `x86real.h` and `decomp.hpp`
One of those per delivery now, eh?

Part of P0189, funded by Arandui and Lmocinemod.
2022-04-16 23:53:46 +02:00
nmlgc 6058395372 [Maintenance] Change the inline assembly keyword to `_asm`
The single underscore version is actually slightly more supported among
the compilers I've seen so far. Also added the exact list now.

Part of P0183, funded by Yanga and [Anonymous].
2022-02-18 09:36:34 +01:00
nmlgc cceb09fc3e [Decompilation] [th01] Sariel: Pattern 12/16
The one where Sariel fires vertical 3-stacks with two spawners moving
from between the two bottom edges of the playfield, followed by
randomly raining bullets from two spawners moving between the two top
edges of the playfield. Final pattern of Sariel's first form, and
surprisingly fair by never spawning pellets on top of Reimu.

Also, about time I found a way of bypassing the -Z -3 function
parameter optimization in order to keep using nice structures like
these.

Part of P0179, funded by Ember2528.
2022-01-31 07:18:43 +01:00
nmlgc ab4c1a9bad [Maintenance] Add a template for stupid bytewise access to logical structures
For the cases where ZUN's code would always be cleaner without it.

Part of P0157, funded by Yanga.
2021-09-12 18:35:08 +02:00
nmlgc aae96aec45 [Decompilation] Find out how to bypass TCC's optimization of 0 immediates
By deferring that immediate 0 to link time. 🤦

Part of P0146, funded by -Tom- and Ember2528.
2021-06-09 23:12:04 +02:00
nmlgc 29abdd5b6a [Maintenance] Make decomp.h exclusive to C++
eeb4e7e changed the final C translation unit that used this header to
C++, and we got some more helpful inline functions upcoming.

Part of P0136, funded by [Anonymous].
2021-03-20 02:17:08 +01:00