Commit Graph

44 Commits

Author SHA1 Message Date
nmlgc 244136c42b [Naming] [th01] Rename grcg_setcolor_tdw() to grcg_setcolor_tcr()
TDW and TCR modes share the same bit in the GRCG mode register and are
thus indistinguishable when looking at a disassembly, but only apply to
writing (TDW) or reading (TCR), respectively. TH01 only performs read
operations in this mode, so it's unambiguously TCR.

Part of P0176, funded by Ember2528.
2022-01-31 07:18:42 +01:00
nmlgc 692e8d1c42 [Naming] [th01] Remove "back/front" terminology from inter-page copy functions
TH01 doesn't use "back" and "front" pages in the way the later games
do, after all. Indicating that the source page of this parameter-less
function is the one that was previously set via graph_accesspage_func()
is going to make pretty much all its call sites way clearer, and stops
implying any further state.

Part of P0167, funded by Ember2528.
2021-11-07 23:27:30 +01:00
nmlgc cf356bbf5e [Maintenance] [th01] Start a new header for commonly used VRAM color indices
Part of P0158, funded by Yanga.
2021-09-28 18:05:24 +02:00
nmlgc e07624a7be [Maintenance] [th01] Start a new header for clamping macros
Part of P0158, funded by Yanga.
2021-09-28 18:05:24 +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 794c6ab55c [Maintenance] Fix another bunch of accumulated typos
Part of P0139, funded by [Anonymous].
2021-05-11 18:47:49 +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 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 0ce869c30a [Maintenance] Complete the master.hpp transition
Part of P0133, funded by [Anonymous].
2021-01-30 19:22:29 +01:00
nmlgc b104b3316b [Maintenance] Consistently use Borland's I/O port intrinsics
Rather than preferring either the Microsoft/Watcom `(in|out)pw?` style,
or the Borland `(in|out)portb?` style, master.lib had to introduce its
own `(OUT|IN)P[BW]` naming scheme… Insert obligatory xkcd standards
comic.

Part of P0126, funded by [Anonymous] and Blue Bolt.
2020-11-15 21:16:40 +01:00
nmlgc e8ae29ca4e [Maintenance] Remove the old `planar(8|16|32)_t` types
All code that used them has transitioned to C++, and can use the
Planar<> template.

Part of P0125, funded by [Anonymous].
2020-11-02 23:04:54 +01:00
nmlgc f1c63ab3a1 [Reverse-engineering] Assign names to all graph_putsa_fx() effects
And get rid of the constraining FX() macro, with its spacing parameter
that we haven't even seen used so far.

Part of P0124, funded by [Anonymous] and Blue Bolt.
2020-11-02 22:33:50 +01:00
nmlgc eb89330f64 [Build] [th01] Move the -Z and -3 options onto the command line
Deactivating them is the exception, not the norm.

Part of P0122, funded by Yanga.
2020-10-06 13:27:33 +02:00
nmlgc b974c1a915 [Maintenance] Add separate macros for GRCG/EGC-accelerated reads and writes
Not only getting rid of the "useless" (and thankfully, consistent)
bitplane parameter, but also allowing those shortened macros to be
redefined for the upcoming little ZUN inconsistency.

Part of P0120, funded by Yanga.
2020-09-28 12:51:01 +02:00
nmlgc ba29539fc7 [Maintenance] Declare a distinct type for VRAM offsets
… and this one, while I'm at it. I've been using pretty much every
possible type for VRAM offset variables, depending on my mood that day,
since signedness apparently never matters for those.
Except that it does. And so, just like with most of our high-level
types, we also have to account for ZUN's little signedness
inconsistencies here. Oh well, at least it's now only one of two types,
and there's no need to choose between `int` or `unsigned int` or
`short` or `unsigned short` or `int16_t` or `uint16_t` or `size_t` or…

Part of P0111, funded by [Anonymous] and Blue Bolt.
2020-08-28 14:53:33 +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 67d35115e6 [Maintenance] Use inline functions for all VRAM offset calculations
At least those can all be moved to a single place.

Part of P0105, funded by Yanga.
2020-08-12 16:16:18 +02:00
nmlgc d840841a2b [Naming] Rename egc_copy_rect_1_to_0() to emphasize its 16-dot alignment
ZUN might have gotten the impression that the EGC can *only* work with
multiples of 16 pixels per load or store? Which might explain why…

Part of P0102, funded by Yanga.
2020-07-12 16:27:56 +02:00
nmlgc 97dce75446 [Maintenance] Proofread all comments in C land 2020-06-21 22:14:08 +02:00
nmlgc f54e05492e [Maintenance] [th01] Rename z_col_at() to z_graph_readdot()
There actually is a master.lib function doing the same!
2020-06-21 22:13:47 +02:00
nmlgc 6a5fa3aee9 [Maintenance] [th01] Decide on `unput` for VRAM page 1 pixel restoration
"Unblitting" reads better in commit descriptions, though 🤔

Part of P0096, funded by Ember2528.
2020-06-13 21:13:48 +02:00
nmlgc 753e1b670a [Decompilation] Change graph_move_byterect_interpage() page parameters to int
Turbo C++ doesn't do the 32-bit PUSH LARGE optimization for 8-bit
parameters?

Part of P0094, funded by Yanga.
2020-05-25 15:15:41 +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 df6b636053 [Decompilation] Add an inline function for VRAM offset calculation
Which actually does inline… in C++, because Turbo C++ doesn't support
the `inline` keyword in C mode. So much for the superiority of that
language, even in 1994…

Part of P0083, funded by Yanga.
2020-03-18 20:11:18 +01:00
nmlgc 54e5bf39fc [Maintenance] Use `dots` for 1bpp lines, and `planar` for B/R/G/E dot structs
I tried `brge` for the latter, but that had *the* most horrible
ergonomics, and I misspelled it as `bgre` 100% of the times I typed it
manually. Turns out that `dots` is also consistent with master.lib's
naming scheme, leaving `planar` to *actually* refer to types storing
multiple planes worth of pixels. These types are showing up more and
more, and deserve something better than their previous long-winded and
misleading name.

Part of P0081, funded by Ember2528.
2020-03-07 21:19:25 +01:00
nmlgc 0252da2a71 [Decompilation] [th01] Game init and exit functions
Yes, that's the code that forgot reactivating the text cursor before
returning to the DOS prompt!

Completes P0080, funded by Ember2528 and Splashman.
2020-03-03 13:12:00 +01:00
nmlgc de3f9ec31b [Decompilation] [th01] Graphics BIOS initialization and activation functions
Just like with the z_text_*() functions, master.lib doesn't already
have graph_init() and graph_exit() either, and once again, ZUN's code
here doesn't fully correspond to any master.lib function. Unlike the
z_text_*() functions though, those names aren't really the best
descriptions for these rather random combinations of BIOS calls and I/O
port writes…

Anyway, that's the entire segment!

Part of P0080, funded by Ember2528 and Splashman.
2020-03-03 13:07:55 +01:00
nmlgc ee682ce2e1 [Decompilation] [th01] Page flipping
No macros here either.

Part of P0080, funded by Ember2528 and Splashman.
2020-03-03 13:07:29 +01: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 7d77338e29 [Decompilation] [th01] Palette fades from and to white and black
Nice lambda functions.

Part of P0080, funded by Ember2528 and Splashman.
2020-03-03 13:04: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 0f18dbc4bd [Decompilation] [th01] Single-point drawing and retrieval
In which our typedefs mercilessly reveal ZUN's original sloppiness, and
the unncessary sign extension taking place here. Also,  unused…

Completes P0069, funded by [Anonymous] and Yanga.
2020-01-14 22:12:18 +01:00
nmlgc b0c832bdee [Decompilation] [th01] Restorable line drawing
Yes, when clipping the start and end points to the screen area, ZUN
uses an integer division to calculate the line slopes, rather than a
floating-point one. Doesn't seem like it actually causes any incorrect
lines to be drawn, though; that case is only hit in the Mima boss
fight, which draws a few lines with a bottom coordinate of 400 rather
than 399. It *might* also restore the wrong pixels at parts of the
YuugenMagan fight, causing weird flickering, but seriously, that's an
issue everywhere you look in this game.

Part of P0069, funded by [Anonymous] and Yanga.
2020-01-14 22:12:08 +01:00
nmlgc 2ac00d47bf [Decompilation] [th01] Box and rectangle drawing
Completes P0068, funded by Yanga.
2020-01-14 22:06:58 +01:00
nmlgc a6d292a62c [Decompilation] [th01] graph_putsa_fx
TH01's (original) version also replicates the PC-98 text RAM's reverse
and underline attributes. Which was removed in later games,
interestingly and inconsistently enough.

Part of P0068, funded by Yanga.
2020-01-14 22:04:12 +01:00
nmlgc ebb30ce170 [Reverse-engineering] [th01] Restorable line and box drawing
Including the longest function present in more than one game among all
of PC-98 Touhou, and #23 on the list of longest functions overall,
which draws a 1-pixel line between two arbitrary pixels.

Completes P0067, funded by Splashman.
2020-01-14 21:53: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 22ebc48eea [Decompilation] [th01] Blocking palette fade-ins from a custom start color
 Unused…

Part of P0067, funded by Splashman.
2020-01-14 21:47:17 +01:00