Commit Graph

2276 Commits

Author SHA1 Message Date
nmlgc f8a774e1dc [Research] Get HOLDKEY.EXE compiling again
And finally compile this directory during the regular build process to
keep this from happening…

Part of P0233, funded by [Anonymous].
2023-03-04 19:40:55 +01:00
nmlgc aa0aad8141 [Platform] [PC-98] Generic byte-aligned sprite blitter
The fact that every sprite format comes with its own blitter is one of
the major sources of bloat in PC-98 Touhou, and of TH01 in particular.
So how about writing a single decently optimized blitter, and calling
into that from the entire game?

Especially because generating distinct blitting functions for every
width is a much better use of all that memory: It eliminates horizontal
loops, and ensures that we use the optimal MOV variant for each sprite
size. Removing any checks for empty bytes (which will turn out to never
have been a good idea for any PC-98 model ever) and unrolling the main
blitting loop using Duff's Device already gets us something that,
depending on the PC-98 model, is easily 2-4× faster than the typical
naive C implementation you'd find in TH01. With master.lib being not
that faster…

Making more use of C++ templates would have been fancy, but horizontal
sprite clipping can change the blit width depending on runtime values.
So, we're back to X macro code generation after all.

Part of P0233, funded by [Anonymous].
2023-03-04 19:40:55 +01:00
nmlgc abeaf851a4 [Platform] [PC-98] EGC rectangle copies
Yup, unaligned! The prefilling case is quite broken on T98-Next, but
given that this emulator hasn't seen any development since 2010 and
every other emulator gets it right, we can reasonably assume that to be
a bug in that emulator.

Completes P0232, funded by [Anonymous].
2023-03-04 19:40:55 +01:00
nmlgc afa6253683 [Platform] [PC-98] GRCG tile and color wrappers
Choosing C++ RAII wrappers because there's at least one case where ZUN
misplaced a manual grcg_off(). This implementation combines safety with
the optimal instructions for both dynamic and static use cases.

Part of P0232, funded by [Anonymous].
2023-02-28 08:08:17 +01:00
nmlgc d15bb0c4fa [Platform] [PC-98] Graphics GDC initialization
I've copy-pasted this snippet so many times, it's time it gets a proper
home.

Part of P0232, funded by [Anonymous].
2023-02-28 08:08:17 +01:00
nmlgc 03519d2af8 [Platform] [PC-98] Font ROM glyph retrieval
Lol @ getting the glyph header field order wrong in 2021…

Part of P0232, funded by [Anonymous].
2023-02-28 08:08:17 +01:00
nmlgc e5d7c9489c [Platform] [PC-98] Gaiji upload
Will come in handy for various research programs… 👀

Part of P0232, funded by [Anonymous].
2023-02-28 08:08:17 +01:00
nmlgc d22c1e6db3 [Platform] [PC-98] Hardware palette setters
Optimally, these are called *at most* once per frame. No need to
micro-optimize here.

Part of P0232, funded by [Anonymous].
2023-02-28 08:08:17 +01:00
nmlgc f1108b5548 [Platform] [PC-98] VSync: Retrigger the VSync interrupt after INT 18h
Well, that didn't take long. Unlike *debugging* this issue after you
encounter it on real hardware…

Part of P0232, funded by [Anonymous].
2023-02-28 08:08:17 +01:00
nmlgc df0672762b [Platform] [PC-98] VSync interrupt handler
Starting with the simple refresh rate-oblivious code from TH01, until
we've figured out what the rest of the master.lib code is doing and
have valid reasons to include it. Also extending the second counter to
32-bit because we *might* be measuring some processes that could take
longer than 19:35 minutes…

Part of P0232, funded by [Anonymous].
2023-02-28 08:08:17 +01:00
nmlgc 82f27f3771 [Platform] [PC-98] Page flipping
Inline functions wouldn't generate optimal code in some cases.

Part of P0232, funded by [Anonymous].
2023-02-28 08:08:17 +01:00
nmlgc 4548b874d6 [Platform] [PC-98] Font ROM glyph types
Moving the code from TH01 to a new platform layer, and deciding against
the `pc98_` prefix, which is sort of implied by the directory of the
header file it came from. Namespaces would be ideal, but Turbo C++ 4.0J
sadly doesn't support them.

Part of P0232, funded by [Anonymous].
2023-02-28 08:08:17 +01: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 e52052abf2 [Maintenance] Introduce EGC register bit count and mask constants
Part of P0232, funded by [Anonymous].
2023-02-28 08:08:17 +01:00
nmlgc bff375d99d [Maintenance] Introduce a VRAM byte bit constant
log₂(BYTE_DOTS), just like SUBPIXEL_FACTOR and SUBPIXEL_BITS.

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 f16144a131 [Naming] Rename peek() and poke() macros to look more intrinsic
And correctly move them to a separate part of x86real.h, as they are
not part of Turbo C++ 4.0J's DOS.H.

Part of P0232, funded by [Anonymous].
2023-02-28 08:08:16 +01:00
nmlgc f7ef7f8f30 [Reverse-engineering] [th01] Packfiles: RLE decompression landmines
The things you find by just switching out the memory allocator…

Part of P0231, funded by [Anonymous].
2023-02-28 08:08:16 +01:00
nmlgc c22299e0c8 [Contributing] Introduce a new "ZUN landmine" label for invisible bugs
Thanks to Clerish for the naming inspiration:

	https://twitter.com/Clerish/status/1623990678937034752

Part of P0231, funded by [Anonymous].
2023-02-28 08:08:10 +01:00
nmlgc 3ba44f08a4 [Contributing] Document the `ZUN bloat`, `ZUN bug`, and `ZUN quirk` labels
In even more detail than we've previously had on the blog.

Part of P0231, funded by [Anonymous].
2023-02-28 08:07:53 +01:00
nmlgc 7191f62dde [Maintenance] [th01] Packfiles: Update to current coding standards
Part of P0231, funded by [Anonymous].
2023-02-28 08:07:53 +01:00
nmlgc 6b5102d2e7 [Platform] [x86 Real Mode] Implement Turbo C++ 4.0J exception handler removal
Full version with support for `operator new`.

Part of P0230, funded by [Anonymous].
2023-02-28 08:07:53 +01:00
nmlgc 4a0d2f3f20 [Maintenance] [th01] Introduce a top/left coordinate type for other branches
I'd really like to keep the semantics in usage code instead of using
`screen_point_t` everywhere.

Part of P0230, funded by [Anonymous].
2023-02-28 08:07:53 +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 8ab99e2feb [Maintenance] [th01] Fix wrong type semantics
Part of P0230, funded by [Anonymous].
2023-02-28 08:07:52 +01:00
nmlgc b326f1df11 [Maintenance] [th01] Endings: Spell out the end_flag condition
Will clarify how the merged frame_delay() function on the `debloated`
branch can switch between binaries.

Part of P0230, funded by [Anonymous].
2023-02-28 08:07:52 +01:00
nmlgc b1487295e8 [Maintenance] [th01] REYHI*.DAT: Fix parameter type of scoredat_name_get()
Part of P0230, funded by [Anonymous].
2023-02-28 08:07:52 +01:00
nmlgc 010d6ae918 [Maintenance] [th01] Interpret redundant resident structure copies as such
And dissolve the "vars" units, which would be too annoying to merge on
the `debloated` branch otherwise. This interpretation of these globals
further highlights the type differences between REIIDEN.EXE and
FUUIN.EXE.
Placing them in directly in `resident.hpp`; on the `debloated` branch,
we could neatly define each of these fields in a matching .cpp file,
but that file would need to be compiled twice due to the aforementioned
differences between binaries. Better to keep those in `op_01.cpp`,
`main_01.cpp`, or `fuuin_01.cpp`, respectively.

Part of P0229, funded by Ember2528.
2023-02-28 08:07:52 +01:00
nmlgc 85c20d325e [Maintenance] Declare correct calling conventions for library code used in TH01
Making these declarations independent of the compiler's default calling
convention used for the game's own code.

Part of P0229, funded by Ember2528.
2023-02-28 08:07:52 +01:00
nmlgc 8e24c92bd9 [Maintenance] [th01] High Score menu: Consistently use the ENDM_A.GRP constant
Part of P0229, funded by Ember2528.
2023-02-28 08:07:52 +01:00
nmlgc 6e9c4c7b9d [Maintenance] [th01] High Score menu: Change pixel macros to constants
Allows us to use them as switch cases in the `debloated` branch, in
exchange for turning some inline functions to macros.

Part of P0229, funded by Ember2528.
2023-02-28 08:07:52 +01:00
nmlgc cb7b67bfe3 [Naming] [th01] Extra bombs per life lost
This variable makes more sense if we name it after its one actual and
consistent usage. All others make more sense when interpreted as a bug
or bloat.

Part of P0229, funded by Ember2528.
2023-02-28 08:07:52 +01:00
nmlgc 357573eaf7 [Naming] [th01] Use a consistent `rem_` prefix for current lives and bombs
Same rationale here – this naming scheme clarifies how these variables
are just redundant copies out of the resident structure.

Part of P0229, funded by Ember2528.
2023-02-28 08:07:52 +01:00
nmlgc e0e9741f92 [Naming] [th01] Use a consistent `credit_` prefix for starting lives
The `credit_` prefix may seem redundant within the REIIDEN.CFG
structure, but consistency seems more important here. Makes it much
easier to follow how these fields are copied around.

Part of P0229, funded by Ember2528.
2023-02-28 08:07:52 +01:00
nmlgc d0dcb5309e [Naming] [th01] .GRP: Palette fade delay frames per step
Part of P0229, funded by Ember2528.
2023-02-28 08:07:52 +01:00
nmlgc 4716948b57 [Maintenance] [th01] Declare types for signed and unsigned scores
Will make it much easier for modders to resolve this inconsistency.

Part of P0229, funded by Ember2528.
2023-02-28 08:07:52 +01:00
nmlgc 841d8be376 [Maintenance] [th01] Stage objects: Define X/Y counts without playfield metrics
Clean subsystem hierarchy restored.

Part of P0229, funded by Ember2528.
2023-02-28 08:07:52 +01:00
nmlgc 24c07c72df [Maintenance] [th01] Replace generic C types with more specific ones
In all places visited during the next 6 pushes: The resident structure
and copies of its values, the packfile implementation, boss entities,
rendering font ROM glyphs to VRAM, and overall inconsistent code
between the three binaries.

Part of P0229, funded by Ember2528.
2023-02-28 08:07:52 +01:00
nmlgc cc42f949e1 [Maintenance] Remove the vsync_reset_*() macros
They obscure the simple nature of these VSync counters more than they
help.

Part of P0229, funded by Ember2528.
2023-02-28 08:07:52 +01:00
nmlgc 9b46ff7d99 [Maintenance] [th01] Move TH01-exclusive VRAM text functions to a new header
Neatly dissolves two of the three game-specific preprocessor branches
in `th01/hardware/grppsafx.h`. Moving at least one function into a
corresponding .cpp file will also simplify the corresponding debloating
commit on the respective branch.

Part of P0229, funded by Ember2528.
2023-02-28 08:07:52 +01:00
nmlgc a309e3f549 [Maintenance] [th01] Avoid direct usage of VRAM plane pointers where possible
Might not read as nicely for the 8-dot cases, but makes it easier to
get rid of the pointers if necessary.

Part of P0229, funded by Ember2528.
2023-02-28 08:07:52 +01:00
nmlgc 41156c0e76 [Maintenance] [th01] .GRP: Describe the format
Part of P0229, funded by Ember2528.
2023-02-28 08:07:52 +01:00
nmlgc fde7152cde [Maintenance] [th01] Remove unnecessary #includes
The route selection literal redefinitions should have been removed in
09d4577.

Part of P0229, funded by Ember2528.
2023-02-28 08:07:52 +01:00
nmlgc b68a61933f [Maintenance] [th01] Bosses: Classify the end-of-boss scene load as ZUN bloat
Part of P0229, funded by Ember2528.
2023-02-28 08:07:52 +01:00
nmlgc 97c16daa0f [Maintenance] [th01] Palettes: Move specific-color flashing to `palette.h`
Part of P0229, funded by Ember2528.
2023-02-28 08:07:52 +01:00
nmlgc 02e12786d3 [Maintenance] [th01] Move the boss post-defeat palette to the palette header
Part of P0229, funded by Ember2528.
2023-02-28 08:07:52 +01:00
nmlgc 7fa4a59796 [Readme] Recommend the new `debloated` branch for nontrivial work
Part of P0229, funded by Ember2528.
2023-02-28 08:07:45 +01:00
nmlgc 3ccaac9d9e [Maintenance] Change Makefile line endings to LF
Part of P0229, funded by Ember2528.
2023-02-28 05:16:54 +01:00
nmlgc 739e1d8ccd [Decompilation] [th05] Lasers: High-level rendering
And that's it, TH05 lasers finalized!

Completes P0228, funded by [Anonymous] and nrook.
2023-01-17 12:19:32 +01:00
nmlgc 034a7db98c [Decompilation] [th05] Lasers: Update function
In which the shrink types """conveniently""" use a signed comparison
that effectively limits their width to 127 pixels, which forces a
shrink/nonshrink distinction upon the entire rest of the code. 🙄

Part of P0228, funded by [Anonymous] and nrook.
2023-01-17 12:16:49 +01:00