Commit Graph

93 Commits

Author SHA1 Message Date
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 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 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 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 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 c7fc4ca41d [Decompilation] [th05] Committing the score delta
Completes P0029, funded by zorg.
2019-09-15 20:29:09 +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 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 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 6ed8e60334 [Reverse-engineering] [th04/th05] Boss phase timeout flag
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 08ffcb0737 [Reverse-engineering] [th04/th05] Boss hitboxes
Funded by -Tom-.
2019-03-01 16:18:02 +01:00
nmlgc 062e775f41 [Reverse-engineering] [th04/th05] .BB file loading boilerplate
Yup, nothing interesting in here.
Except for maybe the confirmation that LS00.BB is used for the curved
bullets used by Shinki and EX-Alice?

Funded by -Tom-.
2019-03-01 16:17:52 +01:00
nmlgc 893bd46969 [Reverse-engineering] [th04/th05] Stage-specific invalidate/render functions
Used only sparingly, like for the starfield in TH05 Stage 2.

Funded by -Tom-.
2019-02-28 17:56:26 +01:00
nmlgc d9e9b38736 [Reverse-engineering] [th04/th05] Spark animation
Also seen when midbosses explode. Class CSparkEffect in uth05win.

Funded by -Tom-.
2019-02-28 17:43:15 +01:00
nmlgc da284cacaf [Reverse-engineering] [th02/th04/th05] Hardcoded spark sprites
As seen when killing stage enemies or grazing.

Funded by -Tom-.
2019-02-28 17:43:15 +01:00
nmlgc b9f3d86e44 [Reverse-engineering] [th04/th05] Adding new player shots
Funded by -Tom-.
2019-02-28 17:43:14 +01:00
nmlgc 9a2c6f72ba [Reverse-engineering] [th04/th05] Second, unused field of the .map header
Thanks to -Tom- for telling me what this obviously had to be.
2019-01-11 00:28:56 +01:00
nmlgc deb45ea14e [Reverse-engineering] [th04/th05] Player shot structure
And that's enough for now, see you in February!

Funded by -Tom-.
2019-01-01 02:29:12 +01:00
nmlgc 35f9bd71e8 [Reduction] [th04/th05] Micro-optimized version of super_roll_put_tiny()
Y'know, maybe ZUN measured and all of this actually mattered? What do I
know?

Funded by -Tom-.
2018-12-31 20:41:13 +01:00
nmlgc e7265ac656 [Reverse-engineering] [th04/th05] Shot X/Y velocity lookup table
Funded by -Tom-.
2018-12-31 19:45:34 +01:00
nmlgc 4770d145d6 [Reverse-engineering] [th04/th05] Target position for homing shots
Funded by -Tom-.
2018-12-30 15:31:26 +01:00
nmlgc 612beb815b [Maintenance] Clean up the confusion between "tiles" and .STD tile sections
Funded by -Tom-.
2018-12-30 02:30:16 +01:00
nmlgc 75763ccd32 [Reverse-engineering] [th04/th05] Invalidating background tiles around a point
…and *now* we can tackle all those entity types that were referencing
this function, with the help of uth05win.

Funded by -Tom-.
2018-12-30 00:19:18 +01:00
nmlgc c00b87ed4f [Reverse-engineering] [th04/th05] Redrawing dirty stage background tiles
Funded by -Tom-.
2018-12-30 00:16:16 +01:00
nmlgc bcc1b7518f [Reverse-engineering] [th04/th05] Applying VRAM scrolling to Y coordinates
Funded by -Tom-.
2018-12-29 18:34:51 +01:00
nmlgc 4fe4c8eed1 [Reverse-engineering] [th04/th05] Scrolling-related variables
Funded by -Tom-.
2018-12-29 18:34:51 +01:00
nmlgc 20d05c1653 [Reverse-engineering] [th04/th05] Rendering all stage background tiles at once
Funded by -Tom-.
2018-12-29 18:34:51 +01:00
nmlgc e1e4f819ed [Reverse-engineering] [th02/th04/th05] Stage background tile ring buffer
Funded by -Tom-.
2018-12-29 17:03:24 +01:00
nmlgc 261d5037ed [Reverse-engineering] [th04/th05] .STD file loading
… because TH04's version of this takes the ASCII stage ID directly from
the resident structure.

So boss battles are simply triggered by setting the background tile
scroll speed to 0? That means…

Funded by zorg.
2018-12-26 17:59:03 +01:00
nmlgc 4a0b973c76 [Reverse-engineering] [th04/th05] Midboss-related function pointers
Funded by zorg.
2018-12-26 17:59:03 +01:00