OK, looks like we got all of the C++ crap out of the way... e~xcept for
another function in TH01's REIIDEN.EXE, of course.
[Binary change] Order of 2 relocations in TH01's FUUIN.EXE.
God, this C++ stuff really is a crappy mess. Even had to manually adjust the
alignments at the end of the the TEXTC segment - and no, the ALIGN directive
remains an inadequate tool random bytes, even more so because TASM's
implementation just pads the space with random bytes. But hey, nice to finally
see some reduction outside of seg000.
[Binary change]
* Order of 3 relocations in all of TH04 and TH05's OP.EXE
* Order of 6 relocations in TH03's OP.EXE and MAIN.EXE, and TH05's MAIN.EXE
and MAINE.EXE
* Order of 9 relocations in all of TH01, TH02's OP.EXE and MAINE.EXE, and
TH03's MAINL.EXE
* Order of 11 relocations in TH02's MAINE.EXE
[Binary change]
* Order of 2 relocations in all executables of TH02, TH03, TH04 and TH05
* Order of 4 relocations in TH01's FUUIN.EXE
* Inserts a new relocation into TH01's REIIDEN.EXE
Yup. 50 functions in a single module, totalling 12,633 bytes, used in all 15
game executables, and no references to any of that in the remaining game code.
[Binary change]
* Order of 3 relocations in all of THO3, TH04 and TH05, TH02's MAIN.EXE and
MAINE.EXE, and TH01's OP.EXE and FUUIN.EXE
* Order of 2 relocations in TH02's OP.EXE and TH01's REIIDEN.EXE
* Inserts a new relocation into TH03's MAIN.EXE
Well. Even after downloading pretty much every (identical) copy of Turbo /
Borland C++ 3, 4, 5 and everything inbetween, I could *not* find the original
source to most of the C++ parts in the runtime. Using the IDA disassemblies
to build their slices is simply the only option.
... Really, though, who cares.
Same for registerbgifont() being a wrapper around registerfarbgifont(). But
at least there, IDA should have noticed something weird. The original delete[]
operator refers to the delete function, so registerbgifont() would have had to
be a wrapper around registerbgidriver(), which of course doesn't make sense,
and IDA claims to *know* these functions...
Lol, "registerbgidriver". Just because the original function is nothing but a
wrapper around free(), and registerbgidriver() is also just a wrapper around
registerfarbgidriver().
Well, great. Why did the trapezoid variables have to be included in this
object file? 10 of the executables don't use them, and there's no way to
locate that one needle in the haystack of uninitialized data now.
Initializing the BSS data to 0 instead of the ? in the original source file
avoids size changes in the MZ header.
[Binary change] Order of 5 relocations in TH04's and TH05's MAIN.EXE.
... yeah, just because ZUN decided to use the C file functions to read
reiiden.cfg for a change. OK, can we *finally* include master.lib's bgm.inc
now?
Lol, these are so similar to __rtl_write and __write that Git's diff treats
reada.asm as a modified copy of writea.asm. Same situation with the CAS file
here, too.
Wow. I just had to miss smem_release() once to find myself with a total of 4
missed functions (+ smem_wget(), bfnt_entry_pat() and
bfnt_extend_header_analysis()) a day later. Blasted tiny model.
And here we have another TASM limitation: INCLUDE file names apparently are
strcpy()'d to a buffer with a fixed size of 32 bytes, causing a crash when
trying to include any file with a longer name. Quality.
Heh, all the references to this function are still expressed in db opcode
form, because IDA couldn't process the self-modifying code in
bfnt_entry_pat(). That's almost practical in our case!
Second biggest master.lib object right there... and apparently, TASM doesn't
support segment prefixes in EQU directives?
And yes, there really is no viable solution for both the NOPCALL problem (the
TASM manual states that these NOPs are inserted during single-pass assembly,
which we can't do) and the complementary jump sequences (which are only
inserted for forward references when specifying the JUMPS directive, which
doesn't seem to work for us either).
Because it just so happens that master.lib's bfnt_header structure contains
an element named "START".
And huh, this suddenly works without changing any assembler or linker
parameters? I swear it didn't when I tried it first.
> "OK, the signal slice is pretty large, let's do it tomorrow"
> stay there for the majority of the day
Oh well, at least it paid off. I *really* should work towards PI loading now,
though.
I don't know anything about ANSI/VT100/??? escape sequences, but after some
quick research, these sequences and their effect seem to be specific to the
PC-98 (although they're implemented as part of DOS, of course).
With seg000 changed to word alignment and all definitions for "func" removed,
the master.lib functions can keep their exact alignment themselves.
[Binary change] db 0 → nop before get_machine_98() in the MAIN.EXE and
MAINE.EXE files of TH04 and TH05, respectively.
Um. Not sure if ZUN used an older version there, or if these additional
branches simply resulted from a lack of optimization...
And I even had to convert the labels to local syntax.
Having thought this over for a while, I've decided to stay with the "include
slice" model for now, due to various bugs and other reasons.
We need to compile for the 386 CPU, but this causes TASM to automatically
default every segment to 32-bit mode, which of course is not what we want (and
no, .MODEL USE16 sadly does not help either). Appending USE16 to every segment
declaration in all included files seems to work, but for some reason, this
messes up certain jump instructions. WTF? And even if it did work, we would
still have to do this for every single file we include.
The alternative would be to build proper libraries and let the linker merge
all the code. This would add a lot of unwarranted complexity to the build
process. Not to mention all the EXTERN statements we'd have to maintain.
Ultimately, all of the C runtime ASM code is going to vanish anyway once we've
completed the reduction step. Once we're there, we can simply link to the
original version of the library. These initial dumps are not pretty, and I see
no point in wasting time on making intermediary stages of development look
pretty.
Since including RULES.ASI from every slice seems a bit inefficient (and even
potentiall harmful, considering the age of the development tools we have to
work with), we'll only include it once at the top of every main dump file.
[Binary change] Relocations in TH01's REIIDEN.EXE, again.
Wow, what a slice. Lots of code, and it comes with its own data declarations
inside the code segment! Since all these functions were originally contained
in one code file, it makes sense to do all 13 in one commit. This removes all
erroneous references to the 'NULL CHECK' string.
[Binary change] This also changes some relocations in TH01's REIIDEN.EXE.
To get anywhere, we must become able to include assembly files that define
their own segments. But this will only work if we include these files in the
order they appear in in our dumps, *starting from the very first one*. And to
include the very first one, we must first get rid of the erroneous references
to the first few bytes of the data segment... and this function happens to be
the first one referencing those.
It begins. And this already shows that the inclusion of TH01's ZUNSOFT.COM
will double the size of all Borland C routines we slice out, because we have
to cover both large and tiny memory models...