8000 Added support for mnemonic mappings by DankRank · Pull Request #17 · thpatch/thtk · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Added support for mnemonic mappings #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 10, 2017
Merged

Added support for mnemonic mappings #17

merged 8 commits into from
May 10, 2017

Conversation

DankRank
Copy link
Member
@DankRank DankRank commented May 7, 2017

This PR adds support for "eclmaps", simple format that I came up with. Here's an example of usage:
$ thecl -d6m my_th6.map ecldata1.ecl ecldata1.ecs
will decode ecldata1 and translate the instructions to mnemonics using mappings my_th6.map.

First line is "eclmap" (signature), all the other lines are entries:
<opcode> <signature> <mnemonic>

  1. Opcode is obviously the opcode.
  2. Signature is supposed to be the format of the arguments. Right now it's unimplemented.
  3. Mnemonic is the mnemonic that the opcode will be translated to/from.

Example:
0 ? noop

The question mark means empty field. (Later you will be able to load multiple mappings and combine them into one.)

Here are some example eclmaps:

map for th06 (source)
map for th13 (source)

fixes #12

DankRank added 8 commits May 6, 2017 09:44
File format is magic line "eclmap", followed by entries:
<opcode> <signature> <mnemonic> # comments

"signature" is supposed to describe opcode arguments. It will be
unimplemented for now, but it's supposed to be replacing hardcoded
id_format_pair_t arrays.

"mnemonic" is the usual C identifier [a-zA-Z_][0-9a-zA-Z_]*. Can't start
with ins_ for obvious reasons.

You can specify "?" as a signature or mnemonic, which basically means
"don't touch this entry". The idea is that one eclmap could have:
123 ? my_awesome_mnemonic
and another one could have:
123 fff ?
but if you load both of them, they will combine into a single entry
(also, possibly combining with built-ins)

Right now you can only load one eclmap, because arguments in thtk are
weird :^)
Originally I wanted there to be checks for when g_eclmap is NULL, but
then I forgot. :^)

This seems like a better solution, because in the end were gonna have
builtins, so it's always going to be allocated.
Someone needs to do the manpages.
@ManDude
Copy link
Collaborator
ManDude commented May 7, 2017

Incomplete th07 eclmap, based on the th06 one.

@DankRank DankRank requested a review from nmlgc May 10, 2017 15:14
}
else {
ent.signature = ptr;
if(ptr[0] == '_') ptr[0] = '\0'; /* allow empty strings to be specified with "_" */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of interest, this is for functions that don't take a parameter?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Contributor
@nmlgc nmlgc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good so far. (In fact, while testing this, I only found some minor portability issues with thecl itself, not with any of this code.) While I definitely prefer to just hardcode those mappings, this is not only a good compromise until we've reverse-engineered eclmaps for all games, but generally a good idea to allow non-developers to identify both old and new games independently from us. (Compiling still is hard, unfortunately.)

What are the plans for the signature? Three things come to mind:

  • Validating incoming eclmaps against the internal tables and immediately throwing an error when a new game changes the format of an instruction introduced in an earlier game.
  • Printing pretty function prototypes at the top of dumped files, as an aid to ECL hackers. (Especially if we end up hardcoding them and they end up not having the mapfiles.)
  • Supplementing the internal function format tables instructions, allowing others to identify newly introduced functions without writing a single line of C code. (As someone who turned thcrap support for new games into a speedrun, I highly approve of this.)

Don't know if you want to extend the format to also cover the main routines of TH06-TH08. Since they assign different functions to the same opcodes, the format would probably need a second "section" introduced by a new magic word. Or we just hardcode that one as a separate eclmap_t once we get to properly dump and lex it, since it doesn't have that many instructions and we're never going to see it again.

Before releasing this, the manpage also needs to be updated.

9036

@nmlgc nmlgc merged commit c011746 into master May 10, 2017
@ManDude ManDude deleted the mnemonics branch October 27, 2019 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Translate known instructions in thecl
3 participants
0