Commit Graph

2286 Commits

Author SHA1 Message Date
nmlgc 6a92122432 [Maintenance] [th02] Remove invalid Shift-JIS code point in `th02_main.asm`
Would otherwise drive me nuts until I get to decompiling Meira.

Part of P0235, funded by Ember2528.
2023-03-25 21:24:47 +01:00
nmlgc e7a9262f50 [Contributing] Remove trailing commas from `public` in a pre-commit hook
Starting more ore less simple with a shell script calling `sed`, which
should work anywhere Git is used.
2023-03-20 01:55:06 +01:00
nmlgc 0685bd0885 [Maintenance] [th03] Remove trailing comma from `public` directive
These break the build on TASM32 version 5.0… which means that
th03_main.asm didn't assemble on that version ever since 3072208.
Thanks to mu021 for telling me about the resulting crash!
2023-03-20 00:29:02 +01:00
nmlgc 3afb73eada [Reverse-engineering] [th01] Pellets: Document missing resets for delay clouds
The exact reason why pellets can be carried over from Sariel's first
form to her second… and why you probably shouldn't carelessly use that
redundant count of alive pellets to skip loops in the Anniversary
Edition, because that count will be incorrect after a reset.
Thanks to mu021 for reporting this issue!
2023-03-14 00:18:23 +01:00
nmlgc 6370f96d9a [Reverse-engineering] [th01] Pellets: Correctly document interlacing
It *does* affect collision detection after all, making removal for the
Anniversary Edition slightly more tricky.

Part of P0234, funded by Ember2528.
2023-03-04 19:40:55 +01:00
nmlgc 6713b1bf9c [Maintenance] [th01] 16× TRAM letters: Fix macro copy-pasting accidents
Part of P0234, funded by Ember2528.
2023-03-04 19:40:55 +01:00
nmlgc dbc5b511ba [Research] BLITPERF: Allow the GRCG sprite color to be customized
spaztron64 suggested that the GRCG might not always write all 4 planes
if one of the tile registers is 0. By changing the color and comparing
the results of this benchmark, we can prove that real hardware has no
such optimization.

Completes P0233, funded by [Anonymous].
2023-03-04 19:40:55 +01:00
nmlgc 12b8bd550d [Research] BLITPERF: Remove seed customization
There's little point to it, and it frees up a letter for…

Part of P0233, funded by [Anonymous].
2023-03-04 19:40:55 +01:00
nmlgc 4837ec7ec9 [Research] Benchmark various sprite blitting approaches
Running this on various PC-98 models confirms that unchecked blitting
(i.e., what you would intuitively consider to be the best method) is in
fact faster than checking either byte of a 16-pixel-wide sprite
beforehand, and has been throughout the PC-98's lifespan. For optimal
performance on the 286 and 386, we might want to use MOVS instead of
MOV, but even that difference is way too small to truly matter.
Also, nice to see turns out that our blitter outperforms a naive pure C
implementation by 2-4×, depending on the model. And master.lib is not
*that* much faster…

The gaiji in `Research/blitperf.bmp` were taken from the Unifont
version 15.0.01 glyphs for:

	• U+2022 BULLET •
	• U+23F1 STOPWATCH ⏱
	• U+1F40C SNAIL 🐌

Part of P0233, funded by [Anonymous].
2023-03-04 19:40:55 +01:00
nmlgc 6514a6b9a5 [Research] Set optimized code generation flags
Taken from the `debloated` branch.

Part of P0233, funded by [Anonymous].
2023-03-04 19:40:55 +01:00
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