Commit Graph

713 Commits

Author SHA1 Message Date
nmlgc f33a3ef220 [Maintenance] [th04/th05] Separate constant for the player↔option distance
Used in pretty much all shot type control functions.

Part of P0036, funded by zorg.
2019-10-14 23:41:57 +02:00
nmlgc b801d24a34 [Reverse-engineering] [th04/th05] Setting the player shot velocity
The TH05 difference: A ridiculous out-of-bounds structure field access.
Could have done safely by just passing a shot_t*, but ZUN's too cool
for that?

Also, about time we started putting the function prototypes directly
into the C headers, and the C headers *only*, upon reverse-engineering…

Part of P0036, funded by zorg.
2019-10-14 23:41:52 +02:00
nmlgc 5ebbe7bda9 [Maintenance] Move all shot-related slices to the player/ subdirectory
It seems that the main th0?/ directories should only contain actual
translation units (of which there are more than previously assumed)
as well as other not really further classifiable slices?

Part of P0036, funded by zorg.
2019-10-14 23:41:46 +02:00
nmlgc a533b5d3ea [Reverse-engineering] [th04/th05] Player sprite area invalidation
And once again, the TH05 version is un-decompilable. :/ It was pretty
close this time, though, as the entire block between PUSH DI and POP DI
kind of resembles a separate inlined function, in accordance with Turbo
C++'s  automatic backup of the DI register, as researched in 7f971a0.

Except that it contains a loop, and Turbo C++ refuses to inline any
function with `do`, `while`, `for`, or `goto`. If it didn't, it would
have totally worked.

Also, yes, C++ class methods are treated identically in this regard.

Oh well. Shot type control functions next, finally!

Completes P0035, funded by zorg.
2019-09-24 22:04:26 +02:00
nmlgc 7887f53ea8 [Maintenance] Move the playfield constants to a separate .inc file
With both 16- and 32-bit build parts soon having full dependency
tracking, having more small includes wins out over having fewer, larger
ones – and also, over having to fix tons of macro conflicts that stem
from most .inc files assuming the context of the big .asm files.

Case in point, including ReC98.inc doesn't work right now without
defining a .MODEL, which is counter-productive for ASM compilation
units.

Part of P0035, funded by zorg.
2019-09-24 22:00:48 +02:00
nmlgc e65cf0d05d [Maintenance] Change a few ASM .inc files to use 8.3 names
Part of P0035, funded by zorg.
2019-09-24 21:58:18 +02:00
nmlgc 290935fe3e [Reverse-engineering] [th04/th05] Player character display
Including options and the death explosions.

Part of P0035, funded by zorg.
2019-09-24 21:58:09 +02:00
nmlgc 68c9a3c79c [Reverse-engineering] [th02/th04/th05] Single-plane sprite display calls
Require understanding a hardware detail, so let's do them all at once.

Part of P0035, funded by zorg.
2019-09-24 21:58:03 +02:00
nmlgc 6f1f36722f [Reverse-engineering] [th01/th02/th04/th05] Player invincibility frames
Completes P0034, funded by zorg.
2019-09-24 21:57:53 +02:00
nmlgc c77a9276d3 [Reverse-engineering] [th04/th05] Death-related variables
Including the confirmation that both games have an 8-frame deathbomb
window.
The placement of the variables is all over the place though, what the
hell?

Part of P0034, funded by zorg.
2019-09-24 21:57:46 +02:00
nmlgc 5a6567e173 [Reverse-engineering] [th04/th05] Number of point items collected
Yes, if you collect more than 255 point items in one TH04 stage, the
counter will overflow to 0.
It's a 16-bit word in both TH02 and TH05.

Part of P0034, funded by zorg.
2019-09-24 21:57:41 +02:00
nmlgc 881f2c671e [Reverse-engineering] [th04/th05] Player option position
They are supposed to lag behind the player's movement by one frame, and
therefore have to be tracked separately.

I would have also included TH02, if it weren't for the weird sprite
indirection system (not storing X and Y positions directly in the
structure, but taking them from a buffer, with their addresses
always changing, WTF?!) that absolutely needs separate attention.

Part of P0034, funded by zorg.
2019-09-24 21:57:35 +02:00
nmlgc b7d204aeec [Reverse-engineering] [th02/th04/th05] Player option sprite number
Part of P0034, funded by zorg.
2019-09-24 21:57:29 +02:00
nmlgc 0b542125a5 [Decompilation] [th04/th05] Remove the Subpixel constructors
They just create unnecessary code when passing Subpixels by value to
functions.

Part of P0034, funded by zorg.
2019-09-24 21:57:23 +02:00
nmlgc 6cdd2296bb [Reverse-engineering] [th04/th05] Input → player movement
Completes P0033, funded by zorg.
2019-09-21 14:01:51 +02:00
nmlgc 7f971a0d1c [Research] Find out why we can't decompile TH05's hud_bar_put()
Part of P0033, funded by zorg.
2019-09-21 14:01:51 +02:00
nmlgc f8213c5a32 [Reverse-engineering] [th04/th05] HUD bar display
So it's *_put(), inherited from master.lib, for everything just writing
to text RAM, and *_render() for everything more involved? But what
about master.lib's own graphics RAM functions like super_put()? Need to
fix that inconsistency some day.

Once again no decompilation, because…

Part of P0033, funded by zorg.
2019-09-21 14:01:50 +02:00
nmlgc e6294c2c1a [Reverse-engineering] [th02/th04/th05] Score update and display
The TH02 version is a piece of cake…

… but TH04 starts turning it into this un-decompilable piece of
unnecessarily micro-optimized ZUN code. Couldn't have chosen anything
better for the first separate ASM translation unit.

Aside from now having to convert names of exported *variables* to
uppercase for visibility in ASM translation units, the most notable
lesson in this was the one about avoiding fixup overflows. From the
Borland C++ Version 4.0 User's Guide:

	"In an assembly language program, a fixup overflow frequently
	 occurs if you have declared an external variable within a
	 segment definition, but this variable actually exists in a
	 different segment."

Can't be restated often enough.

Completes P0032, funded by zorg.
2019-09-21 14:01:47 +02:00
nmlgc 88c05e48e5 [Maintenance] Move a few more ASM definitions to their own .inc files
Part of P0032, funded by zorg.
2019-09-21 13:05:54 +02:00
nmlgc d19f91914e [Maintenance] Mirror the TH04/TH05 C header sharing on the ASM side
Part of P0032, funded by zorg.
2019-09-21 13:04:28 +02:00
nmlgc f07089017f [Maintenance] Rename the extension of game-specific ASM includes to .inc
Rule of thumb going forward: Everything that emits data is .asm,
everything that doesn't is .inc.
(Let's hope that th01_reiiden_2.inc won't exist for that much longer!)

Part of P0032, funded by zorg.
2019-09-21 13:03:56 +02:00
nmlgc b2184e99fd [Maintenance] Remove merge=union from .gitattributes
What the…? *That's* what's been messing up merge conflicts all the
time?

Part of P0032, funded by zorg.
2019-09-21 13:03:17 +02:00
nmlgc 9f764fa6fb [Maintenance] [th04] Split code segment #1 into two
So yes, we *can* technically decompile from anywhere, by splitting the
segment after the function we want, then .SEQuentially GROUPing the two
segments back together into one virtual segment matching the original
one. This gives us one more point where we can slot in new compilation
units that emit their code into the same segment, in the order given on
the link command line.

*But* since all ASM in ReC98 heavily relies on being assembled in MASM
mode, we then start to suffer from MASM's group addressing quirk,
described in the "Accessing data in a segment belonging to a group"
section in the Turbo Assembler Version 5 User's Guide.
Which then forces us to manually prefix every single function call

• from inside the group
• to anywhere else within the newly created segment

with the group name. It's stupidly boring busywork, because of all the
function calls you *mustn't* prefix. Special tooling might make this
easier, but I don't have it, and I'm not getting crowdfunded for it.

And while this is faster than porting the entire codebase to Ideal
mode, I'll only do this on rare occasions.
Like the upcoming, particularly awful piece of reverse-engineering.

Completes P0031, funded by zorg.
2019-09-21 13:02:09 +02:00
nmlgc 3383a4558b [Decompilation] [th05] Resetting boss-related variables
Part of P0031, funded by zorg.
2019-09-21 13:01:30 +02:00
nmlgc b0c2122eec [Decompilation] [th05] Stage-related .BB file loading boilerplate
Yay for alignment, allowing us once again to only move unrelated
variable declarations over to C…

Part of P0031, funded by zorg.
2019-09-21 12:59:22 +02:00
nmlgc e33ccd7ea6 [Maintenance] [th04/th05] Move boss slices into the boss directory
Part of P0031, funded by zorg.
2019-09-21 12:58:09 +02:00
nmlgc dea40ad770 [Decompilation] [th05] Stage setup
"Yeah, let's do this real quick, how can this possibly be hard, it's
just MOVs and a few function calls"…

…except that these MOVs access quite a lot of data, which we now all
have to declare in the C world, hooray.
Once it came to midbosses and bosses, I just turned them into C structs
after all. Despite what I said in 260edd8… after all, the ASM world
doesn't care about the representation in the C world, so they don't
necessarily have to be the same.

Since these structs can't contain everything related to midbosses and
bosses (really, why did all those variables have to be spread out like
this, ZUN?), it also made for a nice occasion to continue the "stuff"
naming scheme, describing "an obviously incomplete collection of
variables related to a thing", first seen in 160d4eb.

Also, PROCDESC apparently is the only syntactically correct option to
declare an extern near proc?

Also, that `boss_phase_timed_out` variable only needs to be here
already because TCC enforces word alignment for the .data segment…
yeah, it's technically not related to this commit, but why waste time
working around it if we can just include that one variable.

Completes P0030, funded by zorg.
2019-09-15 20:35:15 +02:00
nmlgc 9d121c7cce [Decompilation] [th04/th05] Handle subpixels at the C++ type level
I've had the idea to hide this implementation detail and improve code
readability for some time now, but it obviously must still all inline,
to be indistinguishable from a direct assignment of the correct value…

… which, amazingly, it does! Even the static_cast from float to int.
The latter allows us to exclusively implement this for float, since we
do have to express the occasional value smaller than 16.

Who needs macros anyway. Yay, C++ in TH04 and TH05 after all!

Part of P0030, funded by zorg.
2019-09-15 20:30:35 +02:00
nmlgc 0abf84f450 [Maintenance] Add a few missing exports
Part of P0030, funded by zorg.
2019-09-15 20:29:52 +02:00
nmlgc 3b7561a711 [Maintenance] Export all pascal functions with their proper uppercase names
Yup, that was one massive screw-up.

Part of P0030, funded by zorg.
2019-09-15 20:29:47 +02:00
nmlgc e10502bfe6 [Maintenance] Fix the function name format of CDG/CD2 functions
No leading underscore for functions with Pascal calling convention, but
we do have one for all variables, because it's not worth it to put
keywords in front of everything for no reason.
Seemed to have forgotten this rule in 2017?

Part of P0030, funded by zorg.
2019-09-15 20:29:40 +02:00
nmlgc ac2117040c [Decompilation] Define generic function pointer types
Going with the classic pointer-in-typedef approach here, because the
syntax you'd otherwise have to use is terribly inconsistent. It'd be

	 farfunc_t *near near_ptr_to_far_func;

but

	nearfunc_t near *near_ptr_to_near_func;

And that'd hopefully be the last change to ReC98.h for a long time!
Those glacial compile times if every .c file is affected… Really
stands out if your build system is otherwise perfect.

Part of P0030, funded by zorg.
2019-09-15 20:29:32 +02:00
nmlgc c7fc4ca41d [Decompilation] [th05] Committing the score delta
Completes P0029, funded by zorg.
2019-09-15 20:29:09 +02:00
nmlgc 2fb2a65ea8 [Maintenance] Rename the score update/render function
Slightly different in TH04 and TH05, and the TH05 version will be
decompiled in the next push… yeah, not going to worry all too much
about this one right now.

Part of P0029, funded by zorg.
2019-09-15 20:26:38 +02:00
nmlgc 4d7261c5d3 [Reverse-engineering] [th02/th04/th05] (Mid-)Boss update/render function names
Numbers for midbosses, names for bosses, as previous commits already
implied.

Part of P0029, funded by zorg.
2019-09-15 20:26:32 +02:00
nmlgc 789c910c88 [Reverse-engineering] [th04/th05] Playfield fill-around function names
These are used from quite a few places, so it seems best to just name
them after the rect on the playfield they leave out, which is then
typically where the background picture goes.

…*except* that in doing this, we quickly run up against the symbol
length limit of 32 characters. TASM can expand it via the /mv option,
but TCC only lets you *reduce* it to even less. (Why?)
So, my initial idea of `playfield_fill_around_(x)_(y)_(w)_(h)` wouldn't
have worked. But those coordinates are kinda important, I'd say…
Well then, let's just go with `fillm` instead of `fill_around` then.
"Fill with mask at the given coordinates"… yeah, that would work.

Part of P0029, funded by zorg.
2019-09-15 20:26:21 +02:00
nmlgc 6ff427aa0a [Reverse-engineering] [th04/th05] Remaining generic boss variables
… yeah, I don't really like these ambiguous "mode" and "mode change"
variable names either, but what's the alternative? Something something
"sub-phase", to distinguish them from regular phases? Feels way too
early to decide on something more specific. And pretty much nothing I
could come up with right now would have made their inconsistent use any
clearer.
But I need to decide on *something* before moving on, so… eh, let's
just go with what uth05win chose.

Also, yeah, dealing with those 0xFE and 0xFD boss_phase constants some
other time 😛

Also, today in "Weird TASM crashes": Trailing commas at the end of
`public` lines…

Completes P0028, funded by zorg.
2019-09-11 23:19:10 +02:00
nmlgc 260edd8683 [Reverse-engineering] [th04/th05] Remaining generic midboss variables
Turning these into a struct will be very painful with all the
collisions. Not going to do that until we decompiled every single
reference to those.

Part of P0028, funded by zorg.
2019-09-11 18:27:46 +02:00
nmlgc e1714da563 [Maintenance] Move the midboss function pointer slice into its own directory
Part of P0028, funded by zorg.
2019-09-09 18:40:13 +02:00
nmlgc 6023f5c937 [Maintenance] Fix the case of `nearheap[data].asm`'s path
Previously broke the build on repository checkouts created by WSL git,
which enables per-directory case sensitivity for all directories within
the repo:

	https://devblogs.microsoft.com/commandline/per-directory-case-sensitivity-and-wsl/

Nice that this was the only path case issue in the entire repo!
2019-08-14 20:45:05 +02:00
nmlgc 3ba536a2d8 [Reverse-engineering] [th04/th05] Text popups
As in, "HiScore Entry!!", "Extend!!", "Full PowerUp!!", etc.
Class CFloatingText in uth05win… but I decided against naming it like
that because of some stage/BGM title-related variables in the middle.

Funded by -Tom-.
2019-03-06 19:57:23 +01:00
nmlgc fac879f8e6 [Reverse-engineering] [th05] Number display using the bold gaiji font
Many thanks to http://bytepointer.com/tasm/index.htm for providing a
better searchable resource for TASM's default `LEA imm16` → `MOV imm16`
optimization, which we initially had to hack around here.

Funded by -Tom-.
2019-03-06 19:32:38 +01:00
nmlgc ba3a6f7158 [Reverse-engineering] [th05] Shared HUD gaiji row
Yup, yet another random not really needed global.

Funded by -Tom-.
2019-03-06 18:32:07 +01:00
nmlgc 058595b1d9 [Reverse-engineering] [th04/th05] Score variables
In which ZUN uses little-endian BCD as the exclusive internal storage
for both the current and the high score. Which are then updated using,
once again, ridiculously micro-optimized ASM code that uses the
venerable x86 BCD instructions.

Funded by -Tom-.
2019-03-04 21:42:11 +01:00
nmlgc 308d1bc785 [Reverse-engineering] [th04/th05] Boss explosions
So apparently, this way of distorting a circle into an ellipse (?) by
adding a value to the angle for one of the two coordinates isn't
actually widely known in math and doesn't have a name. Fair enough.

Funded by -Tom-.
2019-03-03 14:03:41 +01:00
nmlgc 1cb2c0acbc [Reverse-engineering] [th03/th04/th05] Palette change flag
Funded by -Tom-.
2019-03-03 13:32:55 +01:00
nmlgc 6ed8e60334 [Reverse-engineering] [th04/th05] Boss phase timeout flag
Funded by -Tom-.
2019-03-01 23:20:52 +01:00
nmlgc b02147b5c0 [Reverse-engineering] [th05] Yumeko's Phase 4/7 knife/laser intervals
Which are set in the regular stage init function for some reason,
which is why I have to cover them right now.

Funded by -Tom-.
2019-03-01 23:20:52 +01:00
nmlgc ae9651c693 [Reverse-engineering] [th04/th05] Difficulty/character-based value selection
Funded by -Tom-.
2019-03-01 23:20:51 +01:00
nmlgc c241af414f [Reverse-engineering] Current difficulty
Funded by -Tom-.
2019-03-01 23:07:42 +01:00