Skip to content
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

Reminder: Test converting Battle Script cmd from u8 to u16 #2377

Closed
AsparagusEduardo opened this issue Oct 6, 2022 · 3 comments
Closed

Reminder: Test converting Battle Script cmd from u8 to u16 #2377

AsparagusEduardo opened this issue Oct 6, 2022 · 3 comments

Comments

@AsparagusEduardo
Copy link

ghoulslash Today at 10:16 AM
To disambiguate various we could always make the battle script cmd Id u16 instead of u8, but that would make each cmd run slightly slower than they do now

We need to see how noticeable it would be, as piling stuff in various is starting to get messy.

@mrgriffin
Copy link
Collaborator

An option I thought of back in December would be to have a mixture of one-byte opcodes and two-byte opcodes. For example you could make 0x00-0xEF be one-byte (240 opcodes), and 0xF0 0x00–0xFF 0xFF be two-byte (4096 opcodes), for a total of 4336 opcodes which is probably enough for anybody. You'd then want to put the common stuff nearer the start.

typedef void (*BattleScriptCmdFunc)(const void *args);

static const BattleScriptCmdFunc sBattleScriptCmdFuncs[] =
{
    // ...
};

/* Decodes and executes the current battle script instruction.
 *
 * Opcodes are variable-length and decode to an index into
 * sBattleScriptCmdFuncs.
 * Indexes 0x0000 to 0x00EF are encoded in 1 byte.
 * Indexes 0x00F0 to 0x10EF are encoded in 2 bytes.
 *
 * See also the opcode macro in battle_scripts.inc. */
void RunBattlescriptCurrInstr(void)
{
    const u8 *instr = gBattlescriptCurrInstr;
    u32 index = *instr++;
    if (index >= 0xF0)
    {
        index -= 0xF0;
        index = (index << 8) | *instr++;
        index += 0xF0;
    }
    sBattleScriptCmdFuncs[index](instr);
}
.macro opcode index:req
.if \index < 0xF0
  .byte \index
.elseif \index < 0x10F0
  .byte 0xF0 + ((\index - 0xF0) >> 8)
  .byte (\index - 0xF0) & 0xFF
.else
  .error "Maximum opcode index is 0x10EF"
.endif
.endm

.macro attackcanceler
opcode 0
.endm

.macro accuracycheck failPtr:req, move:req
opcode 1
.4byte \failPtr
.2byte \move
.endm

@DizzyEggg
Copy link
Collaborator

An option I thought of back in December would be to have a mixture of one-byte opcodes and two-byte opcodes. For example you could make 0x00-0xEF be one-byte (240 opcodes), and 0xF0 0x00–0xFF 0xFF be two-byte (4096 opcodes), for a total of 4336 opcodes which is probably enough for anybody. You'd then want to put the common stuff nearer the start.

That's the best option I think. Saves more space this way.

@AsparagusEduardo
Copy link
Author

Closing in favor of #2464

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants