Commit Graph
11 Commits
Author SHA1 Message Date
Nunuhara Cabbage b617449178 aindump/ainedit: initial ain v14 support
Support for Evenicle 2 and Haha Ranman.

There are a few changes in v14:
* a number of new instructions (semantics yet unknown)
* HLL function arguments and return values can now be complex types
  (e.g. arrays, enums)
* support for nested arrays (this isn't necessarily new, but it doesn't
  occur in Rance X at all)
2020-05-17 13:21:37 -07:00
Nunuhara Cabbage 608aedb500 Fix various issues with MSYS2/mingw build 2020-02-14 16:29:44 -08:00
Nunuhara Cabbage a76b7149d9 aindump/ainedit: add .CASE pseudo instruction
Add a pseudo instruction to represent switch case labels, along with the
infrastructure to support pseudo instructions in general. .CASE takes
two arguments: a switch:case index (e.g. "12:8") and the value to match
against.

Also, add a --no-strings option to both programs to allow modifying the
code without changing the string/message tables. This is needed for now
since rebuilding the string/message tables (as currently implemented)
causes serious bugs in Rance X (and probably other games).

Running the following command should produce an ain file that is almost
bit-for-bit identical to the input file (the only difference being minor
drift in floating point constants):

    aindump -c --no-strings in.ain | ainedit -c - --no-strings -o
        out.ain in.ain
2020-02-09 15:34:10 -08:00
Nunuhara Cabbage dab8deca42 Add ainedit utility
The ainedit utility is a tool capable of modifying AIN files up to
version 12 (Rance X). As far as I know, this is the first publicly
released tool that can handle AIN files above version 7.

The basic mode of operation is as follows:

* dump the CODE section with aindump
* edit the disassembled bytecode
* assemble & insert the edited bytebode back into the original AIN file
  using ainedit

E.g.

    aindump -c -o out.jam /path/to/Rance10.ain
    $EDITOR out.jam
    ainedit -c out.jam -o out.ain /path/to/Rance10.ain
    mv /path/to/Rance10.ain /path/to/Rance10.ain.backup
    mv out.ain /path/to/Rance10.ain

ainedit is also capable of editing declarations (structures, functions,
etc.) using the JSON (-j) output from aindump.

There is currently one major deficiency in this tool: it does not
rebuild the AIN file's switch table (SWI0 section). This means that you
can't insert or delete instructions, as it would render the addresses
stored in the switch table invalid. I hope to fix this soon.

A number of changes have also been made to the aindump utility, since
these tools need to work together.
2020-02-07 19:49:39 -08:00
Nunuhara Cabbage e1f6093565 aindump: fix CALLMETHOD argument in v11+
In ain v11+, the first and only argument to CALLMETHOD is the number of
arguments that are being passed to the method. The calling convention
is:

    PUSH <struct page>
    PUSH <function index>
    PUSH <arg 0>
    ...
    PUSH <arg n>
    CALLMETHOD <n>
2020-01-15 14:29:47 -08:00
Nunuhara Cabbage 70a8b9d136 aindump: correct argument types, all syscalls
Use the correct argument types for all instructions, with the exception
of SH_REF_LOCAL_ASSIGN_STRUCTREF2 which I could find an example of.

List all system calls.
2020-01-11 15:05:45 -08:00
Nunuhara Cabbage 8c226ab535 aindump: support code dump up to ain v12 (Rance X)
v11 ain files have 3 new instructions, and 3 modified instructions. It
looks like they decided to break compatibility with this release by
adding arguments to some instructions.

v12 adds one instruction.
2020-01-10 13:38:19 -08:00
Nunuhara Cabbage 55e44b881a aindump: support dumping code up to Heartful Maman
The argument types for many of the newer instructions are likely
still incorrect.
2020-01-10 08:49:25 -08:00
Nunuhara Cabbage 61097cfe73 aindump: option to check xsystem4 compatibility
Add -A,--audit option to check an ain file's compatibility with
xsystem4. Currently only checks for unimplemented instructions and
syscalls.
2020-01-09 19:10:06 -08:00
Nunuhara Cabbage 03e9d59825 aindump: improve disassembler output
Replace many instruction arguments with names/values (strings/messages,
local/global variables, structs, functions, etc.) and add labels to jump
targets.
2020-01-01 20:34:35 -08:00
Nunuhara Cabbage 5d6f148e1b Reorganize project file structure
- Create separate directories for source and header files.
- Build code shared between xsystem4 and aindump as a static library.
- Create header dirs gfx/ system4/ and vm/
- Make CG.c/h usable without a running VM
2019-12-31 17:50:40 -08:00