Commit Graph

48 Commits

Author SHA1 Message Date
nmlgc 51de5ec036 [Decompilation] [th03] SPRITE16: Inline method for sprite size assignments
All but one of the writes to these globals follow the consistent scheme
of assigning hardcoded literals to first `w` and then `h`, so it makes
sense to encapsulate the conversion from display-space pixels to VRAM
words and heights in a method.
(On that note, we also need a new type to encode the notion of
VRAM-space heights as opposed to the display-space heights of
`pixel_t`.)

Part of P0280, funded by [Anonymous], Blue Bolt, and JonathKane.
2024-04-21 13:41:58 +02:00
nmlgc 214c404ef5 [Maintenance] Introduce a type for PC-98 text RAM attributes
No need for signed variants this time!

Part of P0262, funded by [Anonymous] and Blue Bolt.
2023-11-30 18:47:20 +01:00
nmlgc 2c3bd9c16f [Maintenance] `tram_cell_amount_t` can also be used for heights
Part of P0258, funded by [Anonymous] and Blue Bolt.
2023-10-31 22:33:02 +01:00
nmlgc 8943b52167 [Maintenance] Introduce types for VRAM colors and their components
Finally differentiating between colors and columns at least at the type
level.

Part of P0245, funded by [Anonymous], Blue Bolt, Ember2528, and Yanga.
2023-06-30 19:59:11 +02:00
nmlgc 0d28c116c0 [Decompilation] [th02] HUD: Power bar rendering
Which also commits power changes to the shot level…

Part of P0242, funded by Yanga.
2023-06-06 21:37:07 +02:00
nmlgc 9aad9ad114 [Maintenance] Declare 8-bit pixel delta and length types
Part of P0242, funded by Yanga.
2023-06-06 21:02:47 +02:00
nmlgc 9a8e0fc0fd [Maintenance] Move the point structures into `pc98.h`
Unfortunately, it's still premature to start a separate header file for
display-space coordinates like I'm doing with Shuusou Gyoku. What does
make sense, though, is moving the display-space vector types next to
the display-space scalar types in `pc98.h`. This makes much more sense
than keeping them in `master.hpp` just because master.lib also has a
Point type. Would have thought that this lets us remove more than two
`master.hpp` inclusions, though…

Part of P0240, funded by JonathKane.
2023-05-25 15:17:01 +02: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 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 e83d0772b2 [Maintenance] Turn TRAM width types into Shift-JIS width types
These are more generally useful for general text width calculations
that don't necessarily involve TRAM.

Part of P0223, funded by Blue Bolt and rosenrose.
2022-11-30 16:46:35 +01:00
nmlgc b93f216982 [Maintenance] Correctly declare unsigned VRAM byte amount types -.-
Part of P0212, funded by GhostRiderCog, Lmocinemod, and LeyDud.
2022-08-11 18:34:34 +02:00
nmlgc 79e9ab77dc [Maintenance] Simplify EGC macros and hardcode the chip's register size
No reason to continue pretending it supports anything else.

Part of P0212, funded by GhostRiderCog, Lmocinemod, and LeyDud.
2022-08-11 18:03:44 +02:00
nmlgc c99f824f97 [Maintenance] Introduce color component constants
YuugenMagan will need them.

Part of P0207, funded by GhostPhanom.
2022-08-08 20:10:59 +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 01b3b271f6 [Decompilation] [th01] Kikuri: Sprite loading and initial variables
And yes, that's indeed a custom copy constructor, as we're going to see
later.

Part of P0198, funded by Lmocinemod and Ember2528.
2022-06-16 22:51:55 +02:00
nmlgc 00d4b4ab30 [Maintenance] Define a VRAM byte mask constant
Less visual noise.

Part of P0198, funded by Lmocinemod and Ember2528.
2022-06-16 22:50:43 +02:00
nmlgc 73e7667f4f [Maintenance] [th04/th05] Text overlay: Use proper constants for coordinates
The macro syntax highlighting color is always a bit unnerving.

Part of P0186, funded by [Anonymous] and Blue Bolt.
2022-03-27 00:33:51 +01:00
nmlgc 9b28791c7f [Maintenance] [th03] Add a separate type for SPRITE16 sprite area offsets
Part of P0182, funded by Lmocinemod and [Anonymous].
2022-02-18 09:36:34 +01:00
nmlgc 021cbc8e9d [Decompilation] [th01] Boss defeat sequence: SinGyoku version + route selection
Part of P0167, funded by Ember2528.
2021-11-07 23:32:21 +01:00
nmlgc 7cc0189439 [Decompilation] Move palette loops to common macros
You'd really want to overload `operator =` for those.

Part of P0165, funded by Ember2528.
2021-11-07 22:41:39 +01:00
nmlgc c0c0ebc3cd [Decompilation] [th01] Bomb items: Collection and drop callbacks
Second instance of min/max clamping macros being nested into each
other…

Completes P0158, funded by Yanga.
2021-09-28 18:05:24 +02:00
nmlgc 84a3d465dc [Decompilation] [th01] 16× TRAM letters: Single transparent centered kanji
Used for the 東方★靈異伝 effect at the beginning of each scene. Good
that there's this second TRAM page, that's how we can be lazy and just
write into the 26th row :tannedcirno:

Part of P0157, funded by Yanga.
2021-09-12 20:31:41 +02:00
nmlgc b7a10e1a0a [Decompilation] [th01] 16× TRAM letters: Printing fullwidth JIS characters
A small function that prompted lots of research into whether it's
actually correct… which then revealed that every single widely used
PC-98 emulator is broken in this regard. More about that in two
upcoming pushes…

Part of P0157, funded by Yanga.
2021-09-12 20:31:39 +02:00
nmlgc 00ca4ccc1f [Maintenance] Add a COMPONENT_COUNT constant for RGB colors
sizeof(RGB4), seriously?! That's *so* wrong. And also inconsistent next
to COLOR_COUNT everywhere.

Part of P0140, funded by [Anonymous].
2021-05-27 18:49:29 +02: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 ec8be31cd3 [Maintenance] Move PC-98 keyboard declarations to their own header file
140 lines that are only used in, like, 7 translation units.

Part of P0133, funded by [Anonymous].
2021-01-30 18:26:46 +01:00
nmlgc 8266bbd83e [Maintenance] Start a C++ master.lib header file
The regular master.h is big, uncomfortable in C++ mode, and bloated
with all those portability `#define`s that effectively only cover a
small portion of the PC-98-specific code anyway. So, let's gradually
transition to a new smaller header that is more integrated into the
ReC98 codebase, by simply no longer #including `master.h` in new code.

Which also explains its weird place in the root directory. Even though
`libs/master.lib/` contains plenty of game-specific modifications, it
didn't feel right to have anything in this directory refer to types
from `pc98.h`.

Part of P0124, funded by [Anonymous] and Blue Bolt.
2020-11-02 21:12:59 +01:00
nmlgc 97ce07bfc9 [Reverse-engineering] [th03] CDG: VRAM plane iteration
Which is where ZUN adds those additional 0x2000 to make the jump from
the 0xB800 plane to the 0xE000 plane.

Part of P0114, funded by Lmocinemod.
2020-09-07 21:18:38 +02:00
nmlgc d6f634631f [Maintenance] Declare distinct types for pixel and VRAM sizes
Oh wait, we also need one of those for an upcoming structure!

Part of P0111, funded by [Anonymous] and Blue Bolt.
2020-08-28 14:53:33 +02:00
nmlgc 368f151759 [Maintenance] Declare distinct types for screen, VRAM, and TRAM coordinates
Whew, time to look at every `int` variable we ever declared! The best
moment to do this would have been a year ago, but well, better late
than never. No need to communicate that in comments anymore.

These shouldn't be used for widths, heights, or sprite-space
coordinates. Maybe we'll cover that another time, this commit is
already large enough.

Part of P0111, funded by [Anonymous] and Blue Bolt.
2020-08-28 14:53:30 +02:00
nmlgc bd1c2ee7de [Maintenance] #define the number of dots in a byte
One fewer magic number. And one more deliberate dependency on a
PC-98-specific hardware constant, to further drive home just how
unportable these games are, even once decompilation will be complete.

Part of P0105, funded by Yanga.
2020-08-12 16:16:58 +02:00
nmlgc 02f0a0afcc [Build] Don't word-align everything by default
Again, 11 necessary workarounds, vs. forcing byte aligment in at least
18 places, and that number would have significantly grown in the
future.

Part of P0085, funded by -Tom-.
2020-04-03 17:35:57 +02:00
nmlgc 14f9bc3bbe [Decompilation] [th01] Basic hardware palette and GRCG functions
No macros for the port numbers here! Anyone who will try to read and
understand this code will probably want to look those up in PC-98
hardware documentation, and macros would just be an annoying layer of
indirection then.

Part of P0080, funded by Ember2528 and Splashman.
2020-03-03 13:06:34 +01:00
nmlgc 0e852feee8 [Decompilation] [th01] Whole-page color fills and copies
Page… 2? On a system with only page 0 and 1? Had to get out my real
PC-98 to double-check that I wasn't missing anything here, since
every emulator only looks at the bottom bit of the page number. But
real hardware seems to do the same, and there really is nothing special
to it semantically, being equivalent to page 0. 🤷

Part of P0080, funded by Ember2528 and Splashman.
2020-03-03 13:05:49 +01:00
nmlgc 3229b2285d [Decompilation] Encode the per-component range in the RGB color template
Allowing us to then retrieve it using a function call with no run-time
cost, although we do have to be careful with the types here.
Also, is that another solution to decompilation puzzles that involve
types of number literals?

Part of P0080, funded by Ember2528 and Splashman.
2020-03-03 13:02:30 +01:00
nmlgc f2b454dfc6 [Decompilation] Overload operator[] for palettes
Which has no run-time cost in almost all cases.

Part of P0080, funded by Ember2528 and Splashman.
2020-03-03 13:01:27 +01:00
nmlgc 4340b5d6ae [Maintenance] [th01/th02] Split graph_putsa_fx() into its shared parts
I did consider not doing this, because "well, can't anyone who's
*actually* interested just diff the TH01 and TH02 implementations to
figure out the differences themselves", but that duplication ended up
feeling too filthy after all.

And hey, it's a nice excuse to update TH02's version to current naming
standards! 😛

Part of P0068, funded by Yanga.
2020-01-14 22:03:00 +01:00
nmlgc 9f7dde8953 [Decompilation] [th01] Inter-page rectangle moves
Semi-unused, that is, the one use of this function doesn't actually
move the rectangle to a different position. Ironically, the non-moving
back-to-front function immediately above *is* unused…

Also, too bad that stack order is the only reason we can't use structs
to combine all plane variables into a single object.

Part of P0067, funded by Splashman.
2020-01-14 21:50:23 +01:00
nmlgc 6222b78514 [Reverse-engineering] [th01] Current back page
Previously sloppily mis-RE'd as "some page variable, idk", back in
2015…
Now also with a page number typedef. And yeah, restricting bool to C++
has now proven to be stupid after all.

Part of P0067, funded by Splashman.
2020-01-14 21:48:40 +01:00
nmlgc 0e19e52572 [Maintenance] Templatize RGB and palette types for 4- and 8-bit components
Right, PC-98 hardware only supports 4 bits per RGB component, for a
total of 4,096 possible colors. The 8-bit RGB color values we've been
seeing throughout the later games are a master.lib extension, to allow
for more toning precision. Which TH01, with all its NIH syndrome,
doesn't use.

And yup, that means templates in the most basic header files… Since
that would have meant renaming *everything* to compile as C++, I simply
made these types exclusive to C++ code, thcrap style.

Part of P0066, funded by Keyblade Wiedling Neko and Splashman.
2020-01-05 19:06:32 +01:00
nmlgc 80cec5b231 [Reverse-engineering] [th03] 1P/2P selection gaiji cursor
Part of P0064, funded by Touhou Patch Center.
2019-12-29 20:59:34 +01:00
wintiger0222 0b084b83c3 [Reverse-engineering] [th04/th05] graph_putsa_fx 2019-12-17 23:26:54 +01:00
nmlgc 8b01c60f44 [Maintenance] Move PC-98 hardware constants to a separate include file
SPRITE16 would also like to refer to those later.

Part of P0061, funded by Touhou Patch Center.
2019-12-05 21:38:39 +01:00
nmlgc 37fc899c42 Add some useful increment and decrement macros
Which we'd really like to have for the highscore entering screen.
2015-03-01 22:52:25 +01:00
nmlgc 1f514b5a6c [C decompilation] [th02/op] Shot type selection
Oh, OK, so this is what the PC-98 GRCG is all about. You call grcg_setcolor(),
and that puts the PC-98 hardware in some sort of "monochromatic mode". Then,
you just write your pixels into any *single* one of the 4 VRAM bitplanes. This
causes the hardware to automatically write to *all* bitplanes in such a way
that the final palette index for each of the 8, 16, or 32 pixels you just wrote
a 1 value to will actually end up to match the color you set earlier.

Don't forget to call grcg_off() at the end though, or you can't draw any
non-monochromatic graphics, heh.
2015-02-25 23:05:20 +01:00
nmlgc cd33367b51 [C decompilation] [th02/op] Music Room
Yes, all of it. Including the bouncing polygons, of course. And since it's
placed at the end of ZUN's code inside the executable, the code's already
position-independent and fully hackable.
2015-02-24 22:38:44 +01:00
nmlgc a7235304ed Make the VRAM plane constants available to C 2015-02-24 22:16:31 +01:00