From 8e5472044babf1d83c6de82d7083f77d07c3fb34 Mon Sep 17 00:00:00 2001 From: Daan Vanden Bosch Date: Sun, 4 Aug 2019 19:50:02 +0200 Subject: [PATCH] Fixed most issues resulting from opcode typing changes. --- .../resources/scripting/opcodes.yml | 36 +- src/data_formats/parsing/quest/bin.ts | 274 ++++++-------- src/scripting/assembly.test.ts | 29 +- src/scripting/assembly.ts | 21 +- .../ControlFlowGraph.test.ts | 2 +- .../data_flow_analysis/ControlFlowGraph.ts | 101 +++-- .../register_values.test.ts | 11 +- .../data_flow_analysis/register_values.ts | 82 ++-- src/scripting/disassembly.ts | 57 ++- src/scripting/instructions.ts | 87 +++++ src/scripting/opcodes.ts | 349 ++++++++++-------- src/stores/quest_creation.ts | 73 ++-- 12 files changed, 592 insertions(+), 530 deletions(-) create mode 100644 src/scripting/instructions.ts diff --git a/assets_generation/resources/scripting/opcodes.yml b/assets_generation/resources/scripting/opcodes.yml index 31a10e7f..c4219281 100644 --- a/assets_generation/resources/scripting/opcodes.yml +++ b/assets_generation/resources/scripting/opcodes.yml @@ -3687,9 +3687,9 @@ opcodes: - code: 0xf955 mnemonic: bb_exchange_pd_item params: # TODO: determine types - - type: any - - type: any - - type: any + - type: dword + - type: dword + - type: dword - type: instruction_label - type: instruction_label stack: pop @@ -3697,11 +3697,11 @@ opcodes: - code: 0xf956 mnemonic: bb_exchange_pd_srank params: # TODO: determine types - - type: any - - type: any - - type: any - - type: any - - type: any + - type: dword + - type: dword + - type: dword + - type: dword + - type: dword - type: instruction_label - type: instruction_label stack: pop @@ -3709,11 +3709,11 @@ opcodes: - code: 0xf957 mnemonic: bb_exchange_pd_special params: # TODO: determine types - - type: any - - type: any - - type: any - - type: any - - type: any + - type: dword + - type: dword + - type: dword + - type: dword + - type: dword - type: dword - type: instruction_label - type: instruction_label @@ -3722,11 +3722,11 @@ opcodes: - code: 0xf958 mnemonic: bb_exchange_pd_percent params: # TODO: determine types - - type: any - - type: any - - type: any - - type: any - - type: any + - type: dword + - type: dword + - type: dword + - type: dword + - type: dword - type: dword - type: instruction_label - type: instruction_label diff --git a/src/data_formats/parsing/quest/bin.ts b/src/data_formats/parsing/quest/bin.ts index 3b60b812..dbf64c1e 100644 --- a/src/data_formats/parsing/quest/bin.ts +++ b/src/data_formats/parsing/quest/bin.ts @@ -1,13 +1,37 @@ import Logger from "js-logger"; import { Endianness } from "../.."; +import { + Arg, + DataSegment, + Instruction, + InstructionSegment, + Segment, + SegmentType, +} from "../../../scripting/instructions"; +import { + Opcode, + OPCODES, + RegTupRefType, + StackInteraction, + TYPE_BYTE, + TYPE_DWORD, + TYPE_D_LABEL, + TYPE_FLOAT, + TYPE_I_LABEL, + TYPE_I_LABEL_VAR, + TYPE_LABEL, + TYPE_REF, + TYPE_REG_REF, + TYPE_REG_REF_VAR, + TYPE_STRING, + TYPE_S_LABEL, + TYPE_WORD, +} from "../../../scripting/opcodes"; import { ArrayBufferCursor } from "../../cursor/ArrayBufferCursor"; import { Cursor } from "../../cursor/Cursor"; import { ResizableBufferCursor } from "../../cursor/ResizableBufferCursor"; import { WritableCursor } from "../../cursor/WritableCursor"; import { ResizableBuffer } from "../../ResizableBuffer"; -import { Opcode, OPCODES, Type } from "../../../scripting/opcodes"; - -export * from "../../../scripting/opcodes"; const logger = Logger.get("data_formats/parsing/quest/bin"); @@ -23,89 +47,10 @@ export class BinFile { ) {} } -/** - * Instruction invocation. - */ -export class Instruction { - /** - * Byte size of the argument list. - */ - readonly arg_size: number = 0; - /** - * Byte size of the entire instruction, i.e. the sum of the opcode size and all argument sizes. - */ - readonly size: number; - /** - * Maps each parameter by index to its arguments. - */ - readonly param_to_args: Arg[][] = []; - - constructor(readonly opcode: Opcode, readonly args: Arg[]) { - for (let i = 0; i < opcode.params.length; i++) { - const type = opcode.params[i].type; - const arg = args[i]; - this.param_to_args[i] = []; - - if (arg == undefined) { - break; - } - - switch (type) { - case Type.U8Var: - case Type.ILabelVar: - this.arg_size++; - - for (let j = i; j < args.length; j++) { - this.param_to_args[i].push(args[j]); - this.arg_size += args[j].size; - } - - break; - default: - this.arg_size += arg.size; - this.param_to_args[i].push(arg); - break; - } - } - - this.size = opcode.size + this.arg_size; - } -} - -export enum SegmentType { - Instructions, - Data, -} - const SEGMENT_PRIORITY: number[] = []; SEGMENT_PRIORITY[SegmentType.Instructions] = 1; SEGMENT_PRIORITY[SegmentType.Data] = 0; -/** - * Segment of object code. - */ -export type Segment = InstructionSegment | DataSegment; - -export type InstructionSegment = { - type: SegmentType.Instructions; - labels: number[]; - instructions: Instruction[]; -}; - -export type DataSegment = { - type: SegmentType.Data; - labels: number[]; - data: ArrayBuffer; -}; - -/** - * Instruction argument. - */ -export type Arg = { - value: any; - size: number; -}; - export function parse_bin( cursor: Cursor, entry_labels: number[] = [0], @@ -509,10 +454,14 @@ function parse_instructions_segment( const stack: Arg[] = []; for (const instruction of instructions) { - const params = instruction.opcode.params; - const args = instruction.args; + const opcode = instruction.opcode; + const params = opcode.params; + const args = + opcode.stack === StackInteraction.Pop + ? stack.splice(stack.length - params.length, params.length) + : instruction.args; - if (instruction.opcode.push_stack) { + if (opcode.stack === StackInteraction.Push) { for (const arg of args) { stack.push(arg); } @@ -523,16 +472,23 @@ function parse_instructions_segment( let segment_type: SegmentType; switch (param_type) { - case Type.ILabel: + case TYPE_I_LABEL: segment_type = SegmentType.Instructions; break; - case Type.DLabel: + case TYPE_D_LABEL: segment_type = SegmentType.Data; + case TYPE_S_LABEL: + segment_type = SegmentType.String; break; default: continue; } + if (!Number.isInteger(label)) { + logger.error(`Expected label reference but got ${label}.`); + continue; + } + parse_segment( offset_to_segment, label_holder, @@ -543,40 +499,13 @@ function parse_instructions_segment( ); } } - - const stack_params = instruction.opcode.stack_params; - const stack_args = stack.splice(stack.length - stack_params.length, stack_params.length); - - for (let i = 0; i < stack_args.length; i++) { - const param_type = stack_params[i].type; - let label = stack_args[i].value; - let segment_type: SegmentType; - - switch (param_type) { - case Type.ILabel: - segment_type = SegmentType.Instructions; - break; - case Type.DLabel: - segment_type = SegmentType.Data; - break; - default: - continue; - } - - if (!Number.isInteger(label)) { - logger.error(`Expected label reference but got ${label}.`); - continue; - } - - parse_segment(offset_to_segment, label_holder, cursor, label, segment_type, lenient); - } } // Recurse on label drop-through. if ( next_label != undefined && instructions.length && - instructions[instructions.length - 1].opcode !== Opcode.ret + instructions[instructions.length - 1].opcode !== Opcode.RET ) { parse_segment( offset_to_segment, @@ -609,43 +538,25 @@ function parse_instruction_arguments(cursor: Cursor, opcode: Opcode): Arg[] { for (const param of opcode.params) { switch (param.type) { - case Type.U8: + case TYPE_BYTE: args.push({ value: cursor.u8(), size: 1 }); break; - case Type.U16: + case TYPE_WORD: args.push({ value: cursor.u16(), size: 2 }); break; - case Type.U32: - args.push({ value: cursor.u32(), size: 4 }); - break; - case Type.I32: + case TYPE_DWORD: args.push({ value: cursor.i32(), size: 4 }); break; - case Type.F32: + case TYPE_FLOAT: args.push({ value: cursor.f32(), size: 4 }); break; - case Type.RegRef: - args.push({ value: cursor.u8(), size: 1 }); - break; - case Type.ILabel: + case TYPE_LABEL: + case TYPE_I_LABEL: + case TYPE_D_LABEL: + case TYPE_S_LABEL: args.push({ value: cursor.u16(), size: 2 }); break; - case Type.DLabel: - args.push({ value: cursor.u16(), size: 2 }); - break; - case Type.U8Var: - { - const arg_size = cursor.u8(); - args.push(...cursor.u8_array(arg_size).map(value => ({ value, size: 1 }))); - } - break; - case Type.ILabelVar: - { - const arg_size = cursor.u8(); - args.push(...cursor.u16_array(arg_size).map(value => ({ value, size: 2 }))); - } - break; - case Type.String: + case TYPE_STRING: { const start_pos = cursor.position; args.push({ @@ -654,10 +565,28 @@ function parse_instruction_arguments(cursor: Cursor, opcode: Opcode): Arg[] { }); } break; + case TYPE_I_LABEL_VAR: + { + const arg_size = cursor.u8(); + args.push(...cursor.u16_array(arg_size).map(value => ({ value, size: 2 }))); + } + break; + case TYPE_REG_REF: + args.push({ value: cursor.u8(), size: 1 }); + break; + case TYPE_REG_REF_VAR: + { + const arg_size = cursor.u8(); + args.push(...cursor.u8_array(arg_size).map(value => ({ value, size: 1 }))); + } + break; default: - throw new Error( - `Parameter type ${Type[param.type]} (${param.type}) not implemented.` - ); + if (param.type instanceof RegTupRefType) { + args.push({ value: cursor.u8(), size: 1 }); + break; + } else { + throw new Error(`Parameter type ${param.type} not implemented.`); + } } } @@ -693,47 +622,50 @@ function write_object_code( const [arg] = args; switch (param.type) { - case Type.U8: + case TYPE_BYTE: cursor.write_u8(arg.value); break; - case Type.U16: + case TYPE_WORD: cursor.write_u16(arg.value); break; - case Type.U32: - cursor.write_u32(arg.value); + case TYPE_DWORD: + if (arg.value >= 0) { + cursor.write_u32(arg.value); + } else { + cursor.write_i32(arg.value); + } break; - case Type.I32: - cursor.write_i32(arg.value); - break; - case Type.F32: + case TYPE_FLOAT: cursor.write_f32(arg.value); break; - case Type.RegRef: - cursor.write_u8(arg.value); - break; - case Type.ILabel: + case TYPE_LABEL: // Abstract type + case TYPE_I_LABEL: + case TYPE_D_LABEL: + case TYPE_S_LABEL: cursor.write_u16(arg.value); break; - case Type.DLabel: - cursor.write_u16(arg.value); + case TYPE_STRING: + cursor.write_string_utf16(arg.value, arg.size); break; - case Type.U8Var: - cursor.write_u8(args.length); - cursor.write_u8_array(args.map(arg => arg.value)); - break; - case Type.ILabelVar: + case TYPE_I_LABEL_VAR: cursor.write_u8(args.length); cursor.write_u16_array(args.map(arg => arg.value)); break; - case Type.String: - cursor.write_string_utf16(arg.value, arg.size); + case TYPE_REF: // Abstract type + case TYPE_REG_REF: + cursor.write_u8(arg.value); + break; + case TYPE_REG_REF_VAR: + cursor.write_u8(args.length); + cursor.write_u8_array(args.map(arg => arg.value)); break; default: - throw new Error( - `Parameter type ${Type[param.type]} (${ - param.type - }) not implemented.` - ); + if (param.type instanceof RegTupRefType) { + cursor.write_u8(arg.value); + } else { + // TYPE_ANY and TYPE_POINTER cannot be serialized. + throw new Error(`Parameter type ${param.type} not implemented.`); + } } } } diff --git a/src/scripting/assembly.test.ts b/src/scripting/assembly.test.ts index e78a7c62..b8b9079b 100644 --- a/src/scripting/assembly.test.ts +++ b/src/scripting/assembly.test.ts @@ -1,5 +1,6 @@ -import { InstructionSegment, Opcode, SegmentType } from "../data_formats/parsing/quest/bin"; import { assemble } from "./assembly"; +import { InstructionSegment, SegmentType } from "./instructions"; +import { Opcode } from "./opcodes"; test("", () => { const { object_code, warnings, errors } = assemble( @@ -25,10 +26,10 @@ test("", () => { expect(segment_0.type).toBe(SegmentType.Instructions); expect(segment_0.instructions.length).toBe(9); - expect(segment_0.instructions[0].opcode).toBe(Opcode.set_episode); + expect(segment_0.instructions[0].opcode).toBe(Opcode.SET_EPISODE); expect(segment_0.instructions[0].args).toEqual([{ value: 0, size: 4 }]); - expect(segment_0.instructions[1].opcode).toBe(Opcode.bb_map_designate); + expect(segment_0.instructions[1].opcode).toBe(Opcode.BB_MAP_DESIGNATE); expect(segment_0.instructions[1].args).toEqual([ { value: 1, size: 1 }, { value: 2, size: 2 }, @@ -36,21 +37,21 @@ test("", () => { { value: 4, size: 1 }, ]); - expect(segment_0.instructions[2].opcode).toBe(Opcode.arg_pushl); + expect(segment_0.instructions[2].opcode).toBe(Opcode.ARG_PUSHL); expect(segment_0.instructions[2].args).toEqual([{ value: 0, size: 4 }]); - expect(segment_0.instructions[3].opcode).toBe(Opcode.arg_pushw); + expect(segment_0.instructions[3].opcode).toBe(Opcode.ARG_PUSHW); expect(segment_0.instructions[3].args).toEqual([{ value: 150, size: 2 }]); - expect(segment_0.instructions[4].opcode).toBe(Opcode.set_floor_handler); + expect(segment_0.instructions[4].opcode).toBe(Opcode.SET_FLOOR_HANDLER); expect(segment_0.instructions[4].args).toEqual([]); - expect(segment_0.instructions[5].opcode).toBe(Opcode.arg_pushl); + expect(segment_0.instructions[5].opcode).toBe(Opcode.ARG_PUSHL); expect(segment_0.instructions[5].args).toEqual([{ value: 1, size: 4 }]); - expect(segment_0.instructions[6].opcode).toBe(Opcode.arg_pushw); + expect(segment_0.instructions[6].opcode).toBe(Opcode.ARG_PUSHW); expect(segment_0.instructions[6].args).toEqual([{ value: 151, size: 2 }]); - expect(segment_0.instructions[7].opcode).toBe(Opcode.set_floor_handler); + expect(segment_0.instructions[7].opcode).toBe(Opcode.SET_FLOOR_HANDLER); expect(segment_0.instructions[7].args).toEqual([]); - expect(segment_0.instructions[8].opcode).toBe(Opcode.ret); + expect(segment_0.instructions[8].opcode).toBe(Opcode.RET); expect(segment_0.instructions[8].args).toEqual([]); const segment_1 = object_code[1] as InstructionSegment; @@ -58,12 +59,12 @@ test("", () => { expect(segment_1.type).toBe(SegmentType.Instructions); expect(segment_1.instructions.length).toBe(3); - expect(segment_1.instructions[0].opcode).toBe(Opcode.arg_pushl); + expect(segment_1.instructions[0].opcode).toBe(Opcode.ARG_PUSHL); expect(segment_1.instructions[0].args).toEqual([{ value: 1, size: 4 }]); - expect(segment_1.instructions[1].opcode).toBe(Opcode.set_mainwarp); + expect(segment_1.instructions[1].opcode).toBe(Opcode.SET_MAINWARP); expect(segment_1.instructions[1].args).toEqual([]); - expect(segment_1.instructions[2].opcode).toBe(Opcode.ret); + expect(segment_1.instructions[2].opcode).toBe(Opcode.RET); expect(segment_1.instructions[2].args).toEqual([]); const segment_2 = object_code[2] as InstructionSegment; @@ -71,6 +72,6 @@ test("", () => { expect(segment_2.type).toBe(SegmentType.Instructions); expect(segment_2.instructions.length).toBe(1); - expect(segment_2.instructions[0].opcode).toBe(Opcode.ret); + expect(segment_2.instructions[0].opcode).toBe(Opcode.RET); expect(segment_2.instructions[0].args).toEqual([]); }); diff --git a/src/scripting/assembly.ts b/src/scripting/assembly.ts index 0844e348..3c7893d6 100644 --- a/src/scripting/assembly.ts +++ b/src/scripting/assembly.ts @@ -1,16 +1,4 @@ import Logger from "js-logger"; -import { - Arg, - Instruction, - InstructionSegment, - Opcode, - OPCODES_BY_MNEMONIC, - Param, - Segment, - SegmentType, - Type, - DataSegment, -} from "../data_formats/parsing/quest/bin"; import { AssemblyLexer, CodeSectionToken, @@ -22,6 +10,15 @@ import { Token, TokenType, } from "./AssemblyLexer"; +import { + Segment, + Arg, + InstructionSegment, + SegmentType, + Instruction, + DataSegment, +} from "./instructions"; +import { Opcode, OPCODES_BY_MNEMONIC, Param } from "./opcodes"; const logger = Logger.get("scripting/assembly"); diff --git a/src/scripting/data_flow_analysis/ControlFlowGraph.test.ts b/src/scripting/data_flow_analysis/ControlFlowGraph.test.ts index 2ccfafaf..3c67f213 100644 --- a/src/scripting/data_flow_analysis/ControlFlowGraph.test.ts +++ b/src/scripting/data_flow_analysis/ControlFlowGraph.test.ts @@ -1,5 +1,5 @@ -import { InstructionSegment, SegmentType } from "../../data_formats/parsing/quest/bin"; import { assemble } from "../assembly"; +import { InstructionSegment, SegmentType } from "../instructions"; import { BranchType, ControlFlowGraph } from "./ControlFlowGraph"; test("single instruction", () => { diff --git a/src/scripting/data_flow_analysis/ControlFlowGraph.ts b/src/scripting/data_flow_analysis/ControlFlowGraph.ts index 1050b5a6..efdc9932 100644 --- a/src/scripting/data_flow_analysis/ControlFlowGraph.ts +++ b/src/scripting/data_flow_analysis/ControlFlowGraph.ts @@ -1,10 +1,5 @@ -import { - Instruction, - InstructionSegment, - Opcode, - Segment, - SegmentType, -} from "../../data_formats/parsing/quest/bin"; +import { Instruction, InstructionSegment, Segment, SegmentType } from "../instructions"; +import { Opcode } from "../opcodes"; export enum BranchType { None, @@ -74,61 +69,61 @@ export class ControlFlowGraph { switch (inst.opcode) { // Return. - case Opcode.ret: + case Opcode.RET: branch_type = BranchType.Return; branch_labels = []; break; // Unconditional jump. - case Opcode.jmp: + case Opcode.JMP: branch_type = BranchType.Jump; branch_labels = [inst.args[0].value]; break; // Conditional jumps. - case Opcode.jmp_on: - case Opcode.jmp_off: + case Opcode.JMP_ON: + case Opcode.JMP_OFF: branch_type = BranchType.ConditionalJump; branch_labels = [inst.args[0].value]; break; - case Opcode.jmp_e: - case Opcode.jmpi_e: - case Opcode.jmp_ne: - case Opcode.jmpi_ne: - case Opcode.ujmp_g: - case Opcode.ujmpi_g: - case Opcode.jmp_g: - case Opcode.jmpi_g: - case Opcode.ujmp_l: - case Opcode.ujmpi_l: - case Opcode.jmp_l: - case Opcode.jmpi_l: - case Opcode.ujmp_ge: - case Opcode.ujmpi_ge: - case Opcode.jmp_ge: - case Opcode.jmpi_ge: - case Opcode.ujmp_le: - case Opcode.ujmpi_le: - case Opcode.jmp_le: - case Opcode.jmpi_le: + case Opcode.JMP_E: + case Opcode.JMPI_E: + case Opcode.JMP_NE: + case Opcode.JMPI_NE: + case Opcode.UJMP_G: + case Opcode.UJMPI_G: + case Opcode.JMP_G: + case Opcode.JMPI_G: + case Opcode.UJMP_L: + case Opcode.UJMPI_L: + case Opcode.JMP_L: + case Opcode.JMPI_L: + case Opcode.UJMP_GE: + case Opcode.UJMPI_GE: + case Opcode.JMP_GE: + case Opcode.JMPI_GE: + case Opcode.UJMP_LE: + case Opcode.UJMPI_LE: + case Opcode.JMP_LE: + case Opcode.JMPI_LE: branch_type = BranchType.ConditionalJump; branch_labels = [inst.args[2].value]; break; - case Opcode.switch_jmp: + case Opcode.SWITCH_JMP: branch_type = BranchType.ConditionalJump; branch_labels = inst.args.slice(1).map(a => a.value); break; // Calls. - case Opcode.call: + case Opcode.CALL: branch_type = BranchType.Call; branch_labels = [inst.args[0].value]; break; - case Opcode.va_call: + case Opcode.VA_CALL: branch_type = BranchType.Call; branch_labels = [inst.args[0].value]; break; - case Opcode.switch_call: + case Opcode.SWITCH_CALL: branch_type = BranchType.Call; branch_labels = inst.args.slice(1).map(a => a.value); break; @@ -281,46 +276,46 @@ function data_flow( for (const state of out_states) { switch (instruction.opcode) { - case Opcode.let: - case Opcode.flet: + case Opcode.LET: + case Opcode.FLET: state.set( args[0].value, state.get_min(args[1].value), state.get_max(args[1].value) ); break; - case Opcode.leti: - case Opcode.letb: - case Opcode.letw: - case Opcode.leta: - case Opcode.sync_leti: - case Opcode.sync_register: + case Opcode.LETI: + case Opcode.LETB: + case Opcode.LETW: + case Opcode.LETA: + case Opcode.SYNC_LETI: + case Opcode.SYNC_REGISTER: state.set(args[0].value, args[1].value, args[1].value); break; - case Opcode.leto: + case Opcode.LETO: { const info = label_holder.get_info(args[1].value); state.set(args[0].value, info ? info.offset : 0, info ? info.offset : 0); } break; - case Opcode.set: + case Opcode.SET: state.set(args[0].value, 1, 1); break; - case Opcode.clear: + case Opcode.CLEAR: state.set(args[0].value, 0, 0); break; - case Opcode.leti: - case Opcode.letb: - case Opcode.letw: - case Opcode.leta: - case Opcode.sync_leti: - case Opcode.sync_register: + case Opcode.LETI: + case Opcode.LETB: + case Opcode.LETW: + case Opcode.LETA: + case Opcode.SYNC_LETI: + case Opcode.SYNC_REGISTER: state.set(args[0].value, args[1].value, args[1].value); break; // case Opcode.fleti: // state.setf(args[0].value, args[1].value); // break; - case Opcode.rev: + case Opcode.REV: { const reg = args[0].value; const max = state.get_min(reg) <= 0 && state.get_max(reg) >= 0 ? 1 : 0; diff --git a/src/scripting/data_flow_analysis/register_values.test.ts b/src/scripting/data_flow_analysis/register_values.test.ts index 5dc8cb8e..ab7085a9 100644 --- a/src/scripting/data_flow_analysis/register_values.test.ts +++ b/src/scripting/data_flow_analysis/register_values.test.ts @@ -1,5 +1,6 @@ -import { InstructionSegment, Opcode, SegmentType } from "../../data_formats/parsing/quest/bin"; import { assemble } from "../assembly"; +import { InstructionSegment, SegmentType } from "../instructions"; +import { Opcode } from "../opcodes"; import { ControlFlowGraph } from "./ControlFlowGraph"; import { MAX_REGISTER_VALUE, @@ -140,10 +141,10 @@ function test_branched(opcode: Opcode, ...expected: number[]): void { }); } -test_branched(Opcode.addi, 25, 35); -test_branched(Opcode.subi, -5, 5); -test_branched(Opcode.muli, 150, 300); -test_branched(Opcode.divi, 0, 1); +test_branched(Opcode.ADDI, 25, 35); +test_branched(Opcode.SUBI, -5, 5); +test_branched(Opcode.MULI, 150, 300); +test_branched(Opcode.DIVI, 0, 1); test(`${register_values.name} get_random`, () => { const im = to_instructions(` diff --git a/src/scripting/data_flow_analysis/register_values.ts b/src/scripting/data_flow_analysis/register_values.ts index cc0ec53c..d86a2acc 100644 --- a/src/scripting/data_flow_analysis/register_values.ts +++ b/src/scripting/data_flow_analysis/register_values.ts @@ -1,10 +1,5 @@ -import { - Instruction, - Opcode, - RegTupRefType, - TYPE_REG_REF, - TYPE_REG_REF_VAR, -} from "../../data_formats/parsing/quest/bin"; +import { Instruction } from "../instructions"; +import { Opcode, ParamAccess, RegTupRefType } from "../opcodes"; import { BasicBlock, ControlFlowGraph } from "./ControlFlowGraph"; import { ValueSet } from "./ValueSet"; @@ -52,30 +47,30 @@ function find_values( const args = instruction.args; switch (instruction.opcode) { - case Opcode.let: + case Opcode.LET: if (args[0].value === register) { values = find_values(new Set(path), block, i, args[1].value); } break; - case Opcode.leti: - case Opcode.letb: - case Opcode.letw: - case Opcode.sync_leti: + case Opcode.LETI: + case Opcode.LETB: + case Opcode.LETW: + case Opcode.SYNC_LETI: if (args[0].value === register) { values.set_value(args[1].value); } break; - case Opcode.set: + case Opcode.SET: if (args[0].value === register) { values.set_value(1); } break; - case Opcode.clear: + case Opcode.CLEAR: if (args[0].value === register) { values.set_value(0); } break; - case Opcode.rev: + case Opcode.REV: if (args[0].value === register) { const prev_vals = find_values(new Set(path), block, i, register); const prev_size = prev_vals.size(); @@ -89,42 +84,42 @@ function find_values( } } break; - case Opcode.addi: + case Opcode.ADDI: if (args[0].value === register) { values = find_values(new Set(path), block, i, register); values.scalar_add(args[1].value); } break; - case Opcode.subi: + case Opcode.SUBI: if (args[0].value === register) { values = find_values(new Set(path), block, i, register); values.scalar_sub(args[1].value); } break; - case Opcode.muli: + case Opcode.MULI: if (args[0].value === register) { values = find_values(new Set(path), block, i, register); values.scalar_mul(args[1].value); } break; - case Opcode.divi: + case Opcode.DIVI: if (args[0].value === register) { values = find_values(new Set(path), block, i, register); values.scalar_div(args[1].value); } break; - case Opcode.if_zone_clear: + case Opcode.IF_ZONE_CLEAR: if (args[0].value === register) { values.set_interval(0, 1); } break; - case Opcode.get_difflvl: - case Opcode.get_slotnumber: + case Opcode.GET_DIFFLVL: + case Opcode.GET_SLOTNUMBER: if (args[0].value === register) { values.set_interval(0, 3); } break; - case Opcode.get_random: + case Opcode.GET_RANDOM: if (args[1].value === register) { // TODO: undefined values. const min = find_values(new Set(path), block, i, args[0].value).min() || 0; @@ -135,26 +130,41 @@ function find_values( values.set_interval(min, max - 1); } break; + case Opcode.STACK_PUSHM: + case Opcode.STACK_POPM: + { + const min_reg = args[0].value; + const max_reg = args[0].value + args[1].value; + + if (min_reg <= register && register < max_reg) { + values.set_interval(MIN_REGISTER_VALUE, MAX_REGISTER_VALUE); + } + } + break; default: // Assume any other opcodes that write to the register can produce any value. { const params = instruction.opcode.params; - const len = Math.min(args.length, params.length); + const arg_len = Math.min(args.length, params.length); - for (let j = 0; j < len; j++) { + outer: for (let j = 0; j < arg_len; j++) { const param = params[j]; - const val = args[j].value; - if (param.write) { - if ( - (param.type instanceof RegTupRefType && - register >= val && - register < val + param.type.registers.length) || - (param.type === TYPE_REG_REF && val.includes(register)) || - (param.type === TYPE_REG_REF_VAR && val.includes(register)) - ) { - values.set_interval(MIN_REGISTER_VALUE, MAX_REGISTER_VALUE); - break; + if (param.type instanceof RegTupRefType) { + const reg_ref = args[j].value; + let k = 0; + + for (const reg_param of param.type.registers) { + if ( + (reg_param.access === ParamAccess.Write || + reg_param.access === ParamAccess.ReadWrite) && + reg_ref + k === register + ) { + values.set_interval(MIN_REGISTER_VALUE, MAX_REGISTER_VALUE); + break outer; + } + + k++; } } } diff --git a/src/scripting/disassembly.ts b/src/scripting/disassembly.ts index 749e62f4..4c4a5bb7 100644 --- a/src/scripting/disassembly.ts +++ b/src/scripting/disassembly.ts @@ -1,4 +1,13 @@ -import { Arg, Param, Segment, SegmentType, Type } from "../data_formats/parsing/quest/bin"; +import { Arg, Segment, SegmentType } from "./instructions"; +import { + Param, + StackInteraction, + TYPE_STRING, + TYPE_I_LABEL_VAR, + TYPE_REG_REF_VAR, + TYPE_REG_REF, + RegTupRefType, +} from "./opcodes"; /** * @param manual_stack If true, will output stack management instructions (argpush variants). Otherwise the arguments of stack management instructions will be output as arguments to the instruction that pops them from the stack. @@ -53,26 +62,27 @@ export function disassemble(object_code: Segment[], manual_stack: boolean = fals if (line.length > 4) { lines.push(line); } + } else if (segment.type === SegmentType.String) { + lines.push(" " + segment.value); } else { for (const instruction of segment.instructions) { - if (!manual_stack && instruction.opcode.push_stack) { + if (!manual_stack && instruction.opcode.stack === StackInteraction.Push) { stack.push(...instruction.args); } else { - let args = args_to_strings(instruction.opcode.params, instruction.args); + let args: string[] = []; - if (!manual_stack) { - args.push( - ...args_to_strings( - instruction.opcode.stack_params, + if (instruction.opcode.stack === StackInteraction.Pop) { + if (!manual_stack) { + args = args_to_strings( + instruction.opcode.params, stack.splice( - Math.max( - 0, - stack.length - instruction.opcode.stack_params.length - ), - instruction.opcode.stack_params.length + Math.max(0, stack.length - instruction.opcode.params.length), + instruction.opcode.params.length ) - ) - ); + ); + } + } else { + args = args_to_strings(instruction.opcode.params, instruction.args); } lines.push( @@ -106,21 +116,28 @@ function args_to_strings(params: Param[], args: Arg[]): string[] { } switch (type) { - case Type.U8Var: - case Type.ILabelVar: + case TYPE_I_LABEL_VAR: for (; i < args.length; i++) { arg_strings.push(args[i].value.toString()); } - break; - case Type.RegRef: + case TYPE_REG_REF_VAR: + for (; i < args.length; i++) { + arg_strings.push("r" + args[i].value); + } + break; + case TYPE_REG_REF: arg_strings.push("r" + arg.value); break; - case Type.String: + case TYPE_STRING: arg_strings.push(JSON.stringify(arg.value)); break; default: - arg_strings.push(arg.value.toString()); + if (type instanceof RegTupRefType) { + arg_strings.push("r" + arg.value); + } else { + arg_strings.push(arg.value.toString()); + } break; } } diff --git a/src/scripting/instructions.ts b/src/scripting/instructions.ts new file mode 100644 index 00000000..c5cc00c0 --- /dev/null +++ b/src/scripting/instructions.ts @@ -0,0 +1,87 @@ +import { TYPE_I_LABEL_VAR, TYPE_REG_REF_VAR, Opcode } from "./opcodes"; + +/** + * Instruction invocation. + */ +export class Instruction { + /** + * Byte size of the argument list. + */ + readonly arg_size: number = 0; + /** + * Byte size of the entire instruction, i.e. the sum of the opcode size and all argument sizes. + */ + readonly size: number; + /** + * Maps each parameter by index to its arguments. + */ + readonly param_to_args: Arg[][] = []; + + constructor(readonly opcode: Opcode, readonly args: Arg[]) { + for (let i = 0; i < opcode.params.length; i++) { + const type = opcode.params[i].type; + const arg = args[i]; + this.param_to_args[i] = []; + + if (arg == undefined) { + break; + } + + switch (type) { + case TYPE_I_LABEL_VAR: + case TYPE_REG_REF_VAR: + this.arg_size++; + + for (let j = i; j < args.length; j++) { + this.param_to_args[i].push(args[j]); + this.arg_size += args[j].size; + } + + break; + default: + this.arg_size += arg.size; + this.param_to_args[i].push(arg); + break; + } + } + + this.size = opcode.size + this.arg_size; + } +} + +/** + * Instruction argument. + */ +export type Arg = { + value: any; + size: number; +}; + +export enum SegmentType { + Instructions, + Data, + String, +} + +/** + * Segment of object code. + */ +export type Segment = InstructionSegment | DataSegment | StringSegment; + +export type InstructionSegment = { + type: SegmentType.Instructions; + labels: number[]; + instructions: Instruction[]; +}; + +export type DataSegment = { + type: SegmentType.Data; + labels: number[]; + data: ArrayBuffer; +}; + +export type StringSegment = { + type: SegmentType.String; + labels: number[]; + value: string; +}; diff --git a/src/scripting/opcodes.ts b/src/scripting/opcodes.ts index d122725f..550bca6e 100644 --- a/src/scripting/opcodes.ts +++ b/src/scripting/opcodes.ts @@ -1,83 +1,76 @@ /** - * Opcode parameter type. + * Abstract super type of all types. */ -export class Type {} -export const TYPE = new Type(); +class AnyType {} -export class ValueType extends Type {} -export const TYPE_VALUE = new ValueType(); - -export class RefType extends Type {} -export const TYPE_REF = new RefType(); +/** + * Abstract super type of all value types. + */ +class ValueType extends AnyType {} /** * 8-Bit integer. */ class ByteType extends ValueType {} -export const TYPE_BYTE = new ByteType(); /** * 16-Bit integer. */ class WordType extends ValueType {} -export const TYPE_WORD = new WordType(); /** * 32-Bit integer. */ class DWordType extends ValueType {} -export const TYPE_DWORD = new DWordType(); /** * 32-Bit floating point number. */ class FloatType extends ValueType {} -export const TYPE_FLOAT = new FloatType(); /** - * Named reference to a segment of the object code. + * Abstract super type of all label types. */ class LabelType extends ValueType {} -export const TYPE_LABEL = new LabelType(); /** * Named reference to an instruction. */ class ILabelType extends LabelType {} -export const TYPE_I_LABEL = new ILabelType(); /** * Named reference to a data segment. */ class DLabelType extends LabelType {} -export const TYPE_D_LABEL = new DLabelType(); /** * Named reference to a string segment. */ class SLabelType extends LabelType {} -export const TYPE_S_LABEL = new SLabelType(); /** * String of arbitrary size. */ class StringType extends ValueType {} -export const TYPE_STRING = new StringType(); /** * Arbitrary amount of instruction labels. */ class ILabelVarType extends ValueType {} -export const TYPE_I_LABEL_VAR = new ILabelVarType(); + +/** + * Abstract super type of all reference types. + */ +class RefType extends AnyType {} /** * Reference to one or more registers. */ class RegRefType extends RefType {} -export const TYPE_REG_REF = new RegRefType(); /** * Reference to a fixed amount of consecutive registers of specific types. + * The only parameterized type. */ export class RegTupRefType extends RefType { readonly registers: Param[]; @@ -92,11 +85,39 @@ export class RegTupRefType extends RefType { * Arbitrary amount of register references. */ class RegRefVarType extends RefType {} -export const TYPE_REG_REF_VAR = new RegRefVarType(); -class PointerType extends Type {} +/** + * Raw memory pointer. + */ +class PointerType extends AnyType {} + +// Singleton type constants. +// All types except `RegTupRefType` have a single instance. +export const TYPE_ANY = new AnyType(); +export const TYPE_VALUE = new ValueType(); +export const TYPE_BYTE = new ByteType(); +export const TYPE_WORD = new WordType(); +export const TYPE_DWORD = new DWordType(); +export const TYPE_FLOAT = new FloatType(); +export const TYPE_LABEL = new LabelType(); +export const TYPE_I_LABEL = new ILabelType(); +export const TYPE_D_LABEL = new DLabelType(); +export const TYPE_S_LABEL = new SLabelType(); +export const TYPE_STRING = new StringType(); +export const TYPE_I_LABEL_VAR = new ILabelVarType(); +export const TYPE_REF = new RefType(); +export const TYPE_REG_REF = new RegRefType(); +// No singleton constant for `RegTupRefType` because it is parameterized. +export const TYPE_REG_REF_VAR = new RegRefVarType(); export const TYPE_POINTER = new PointerType(); +export const MIN_SIGNED_DWORD_VALUE = -Math.pow(2, 31); +export const MAX_SIGNED_DWORD_VALUE = Math.pow(2, 31) - 1; +export const MIN_UNSIGNED_DWORD_VALUE = 0; +export const MAX_UNSIGNED_DWORD_VALUE = Math.pow(2, 32) - 1; +export const MIN_DWORD_VALUE = MIN_SIGNED_DWORD_VALUE; +export const MAX_DWORD_VALUE = MAX_UNSIGNED_DWORD_VALUE; + export enum ParamAccess { Read, Write, @@ -104,7 +125,7 @@ export enum ParamAccess { } export class Param { - type: Type; + type: AnyType; /** * Documentation string. */ @@ -114,7 +135,7 @@ export class Param { */ access?: ParamAccess; - constructor(type: Type, doc?: string, access?: ParamAccess) { + constructor(type: AnyType, doc?: string, access?: ParamAccess) { this.type = type; this.doc = doc; this.access = access; @@ -301,7 +322,7 @@ export class Opcode { undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -713,12 +734,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -747,12 +768,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -1081,7 +1102,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -1094,7 +1115,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -1141,7 +1162,7 @@ export class Opcode { "Pushes the value of the given register onto the stack.", [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -1196,12 +1217,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -1321,7 +1342,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -1369,7 +1390,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -1396,7 +1417,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -1438,7 +1459,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -1534,7 +1555,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -1554,7 +1575,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -1567,7 +1588,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -1580,7 +1601,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -1600,7 +1621,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -1818,7 +1839,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -1871,7 +1892,7 @@ export class Opcode { undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), "Object handle.", undefined ), @@ -1901,7 +1922,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -2026,7 +2047,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -2102,7 +2123,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), "Object handle.", undefined ), @@ -2115,12 +2136,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -2133,12 +2154,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -2151,12 +2172,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -2178,7 +2199,7 @@ export class Opcode { undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -2191,12 +2212,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -2271,7 +2292,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -2305,7 +2326,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -2359,7 +2380,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -2408,7 +2429,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -2435,12 +2456,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -2551,7 +2572,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -2579,7 +2600,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -2592,7 +2613,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -2647,7 +2668,7 @@ export class Opcode { [ new Param(TYPE_DWORD, undefined, undefined), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -2660,12 +2681,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -2678,7 +2699,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -2699,7 +2720,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -2809,7 +2830,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -2829,7 +2850,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -2884,7 +2905,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -3182,7 +3203,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -3195,7 +3216,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -3208,7 +3229,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -3799,12 +3820,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -3817,12 +3838,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -3835,12 +3856,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -3853,7 +3874,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -3866,7 +3887,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -3921,7 +3942,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -4076,12 +4097,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -4094,7 +4115,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -4127,12 +4148,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -4187,12 +4208,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -4205,7 +4226,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -4219,7 +4240,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -4232,7 +4253,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -4245,7 +4266,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -4258,7 +4279,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -4391,7 +4412,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -4418,7 +4439,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -4494,7 +4515,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -4528,7 +4549,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -4674,7 +4695,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -4694,7 +4715,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -4707,7 +4728,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -4720,7 +4741,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -4778,12 +4799,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -4814,7 +4835,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -4957,7 +4978,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -4971,7 +4992,7 @@ export class Opcode { [ new Param(TYPE_DWORD, undefined, undefined), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -5009,7 +5030,7 @@ export class Opcode { new Param(TYPE_DWORD, undefined, undefined), new Param(TYPE_DWORD, undefined, undefined), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -5023,12 +5044,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -5042,12 +5063,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -5060,12 +5081,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -5106,7 +5127,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -5119,7 +5140,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -5132,7 +5153,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -5145,12 +5166,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -5163,12 +5184,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -5181,12 +5202,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -5199,12 +5220,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -5217,12 +5238,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -5235,12 +5256,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -5253,12 +5274,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -5271,12 +5292,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -5321,7 +5342,7 @@ export class Opcode { new Param(TYPE_DWORD, undefined, undefined), new Param(TYPE_DWORD, undefined, undefined), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -5335,7 +5356,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Read)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Read)), undefined, undefined ), @@ -5924,12 +5945,12 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -5974,7 +5995,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -5987,7 +6008,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -6064,7 +6085,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -6133,7 +6154,7 @@ export class Opcode { [ new Param(TYPE_DWORD, undefined, undefined), new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -6160,7 +6181,7 @@ export class Opcode { undefined, [ new Param( - new RegTupRefType(new Param(TYPE, undefined, ParamAccess.Write)), + new RegTupRefType(new Param(TYPE_ANY, undefined, ParamAccess.Write)), undefined, undefined ), @@ -6424,9 +6445,9 @@ export class Opcode { "bb_exchange_pd_item", undefined, [ - new Param(TYPE, undefined, undefined), - new Param(TYPE, undefined, undefined), - new Param(TYPE, undefined, undefined), + new Param(TYPE_DWORD, undefined, undefined), + new Param(TYPE_DWORD, undefined, undefined), + new Param(TYPE_DWORD, undefined, undefined), new Param(TYPE_I_LABEL, undefined, undefined), new Param(TYPE_I_LABEL, undefined, undefined), ], @@ -6437,11 +6458,11 @@ export class Opcode { "bb_exchange_pd_srank", undefined, [ - new Param(TYPE, undefined, undefined), - new Param(TYPE, undefined, undefined), - new Param(TYPE, undefined, undefined), - new Param(TYPE, undefined, undefined), - new Param(TYPE, undefined, undefined), + new Param(TYPE_DWORD, undefined, undefined), + new Param(TYPE_DWORD, undefined, undefined), + new Param(TYPE_DWORD, undefined, undefined), + new Param(TYPE_DWORD, undefined, undefined), + new Param(TYPE_DWORD, undefined, undefined), new Param(TYPE_I_LABEL, undefined, undefined), new Param(TYPE_I_LABEL, undefined, undefined), ], @@ -6452,11 +6473,11 @@ export class Opcode { "bb_exchange_pd_special", undefined, [ - new Param(TYPE, undefined, undefined), - new Param(TYPE, undefined, undefined), - new Param(TYPE, undefined, undefined), - new Param(TYPE, undefined, undefined), - new Param(TYPE, undefined, undefined), + new Param(TYPE_DWORD, undefined, undefined), + new Param(TYPE_DWORD, undefined, undefined), + new Param(TYPE_DWORD, undefined, undefined), + new Param(TYPE_DWORD, undefined, undefined), + new Param(TYPE_DWORD, undefined, undefined), new Param(TYPE_DWORD, undefined, undefined), new Param(TYPE_I_LABEL, undefined, undefined), new Param(TYPE_I_LABEL, undefined, undefined), @@ -6468,11 +6489,11 @@ export class Opcode { "bb_exchange_pd_percent", undefined, [ - new Param(TYPE, undefined, undefined), - new Param(TYPE, undefined, undefined), - new Param(TYPE, undefined, undefined), - new Param(TYPE, undefined, undefined), - new Param(TYPE, undefined, undefined), + new Param(TYPE_DWORD, undefined, undefined), + new Param(TYPE_DWORD, undefined, undefined), + new Param(TYPE_DWORD, undefined, undefined), + new Param(TYPE_DWORD, undefined, undefined), + new Param(TYPE_DWORD, undefined, undefined), new Param(TYPE_DWORD, undefined, undefined), new Param(TYPE_I_LABEL, undefined, undefined), new Param(TYPE_I_LABEL, undefined, undefined), diff --git a/src/stores/quest_creation.ts b/src/stores/quest_creation.ts index 3f6f5256..7c2f8618 100644 --- a/src/stores/quest_creation.ts +++ b/src/stores/quest_creation.ts @@ -1,7 +1,8 @@ -import { Instruction, Opcode, SegmentType } from "../data_formats/parsing/quest/bin"; import { Vec3 } from "../data_formats/vector"; import { Episode, NpcType, ObjectType, Quest, QuestNpc, QuestObject } from "../domain"; import { area_store } from "./AreaStore"; +import { SegmentType, Instruction } from "../scripting/instructions"; +import { Opcode } from "../scripting/opcodes"; export function create_new_quest(episode: Episode): Quest { if (episode === Episode.II) throw new Error("Episode II not yet supported."); @@ -22,52 +23,52 @@ export function create_new_quest(episode: Episode): Quest { labels: [0], type: SegmentType.Instructions, instructions: [ - new Instruction(Opcode.set_episode, [{ value: 0, size: 4 }]), - new Instruction(Opcode.arg_pushl, [{ value: 0, size: 4 }]), - new Instruction(Opcode.arg_pushw, [{ value: 150, size: 2 }]), - new Instruction(Opcode.set_floor_handler, []), - new Instruction(Opcode.bb_map_designate, [ + new Instruction(Opcode.SET_EPISODE, [{ value: 0, size: 4 }]), + new Instruction(Opcode.ARG_PUSHL, [{ value: 0, size: 4 }]), + new Instruction(Opcode.ARG_PUSHW, [{ value: 150, size: 2 }]), + new Instruction(Opcode.SET_FLOOR_HANDLER, []), + new Instruction(Opcode.BB_MAP_DESIGNATE, [ { value: 0, size: 1 }, { value: 0, size: 2 }, { value: 0, size: 1 }, { value: 0, size: 1 }, ]), - new Instruction(Opcode.ret, []), + new Instruction(Opcode.RET, []), ], }, { labels: [150], type: SegmentType.Instructions, instructions: [ - new Instruction(Opcode.leti, [{ value: 60, size: 1 }, { value: 237, size: 4 }]), - new Instruction(Opcode.leti, [{ value: 61, size: 1 }, { value: 0, size: 4 }]), - new Instruction(Opcode.leti, [{ value: 62, size: 1 }, { value: 333, size: 4 }]), - new Instruction(Opcode.leti, [{ value: 63, size: 1 }, { value: -15, size: 4 }]), - new Instruction(Opcode.arg_pushl, [{ value: 0, size: 4 }]), - new Instruction(Opcode.arg_pushr, [{ value: 60, size: 1 }]), - new Instruction(Opcode.p_setpos, []), - new Instruction(Opcode.leti, [{ value: 60, size: 1 }, { value: 255, size: 4 }]), - new Instruction(Opcode.leti, [{ value: 61, size: 1 }, { value: 0, size: 4 }]), - new Instruction(Opcode.leti, [{ value: 62, size: 1 }, { value: 338, size: 4 }]), - new Instruction(Opcode.leti, [{ value: 63, size: 1 }, { value: -43, size: 4 }]), - new Instruction(Opcode.arg_pushl, [{ value: 1, size: 4 }]), - new Instruction(Opcode.arg_pushr, [{ value: 60, size: 1 }]), - new Instruction(Opcode.p_setpos, []), - new Instruction(Opcode.leti, [{ value: 60, size: 1 }, { value: 222, size: 4 }]), - new Instruction(Opcode.leti, [{ value: 61, size: 1 }, { value: 0, size: 4 }]), - new Instruction(Opcode.leti, [{ value: 62, size: 1 }, { value: 322, size: 4 }]), - new Instruction(Opcode.leti, [{ value: 63, size: 1 }, { value: 25, size: 4 }]), - new Instruction(Opcode.arg_pushl, [{ value: 2, size: 4 }]), - new Instruction(Opcode.arg_pushr, [{ value: 60, size: 1 }]), - new Instruction(Opcode.p_setpos, []), - new Instruction(Opcode.leti, [{ value: 60, size: 1 }, { value: 248, size: 4 }]), - new Instruction(Opcode.leti, [{ value: 61, size: 1 }, { value: 0, size: 4 }]), - new Instruction(Opcode.leti, [{ value: 62, size: 1 }, { value: 323, size: 4 }]), - new Instruction(Opcode.leti, [{ value: 63, size: 1 }, { value: -20, size: 4 }]), - new Instruction(Opcode.arg_pushl, [{ value: 3, size: 4 }]), - new Instruction(Opcode.arg_pushr, [{ value: 60, size: 1 }]), - new Instruction(Opcode.p_setpos, []), - new Instruction(Opcode.ret, []), + new Instruction(Opcode.LETI, [{ value: 60, size: 1 }, { value: 237, size: 4 }]), + new Instruction(Opcode.LETI, [{ value: 61, size: 1 }, { value: 0, size: 4 }]), + new Instruction(Opcode.LETI, [{ value: 62, size: 1 }, { value: 333, size: 4 }]), + new Instruction(Opcode.LETI, [{ value: 63, size: 1 }, { value: -15, size: 4 }]), + new Instruction(Opcode.ARG_PUSHL, [{ value: 0, size: 4 }]), + new Instruction(Opcode.ARG_PUSHR, [{ value: 60, size: 1 }]), + new Instruction(Opcode.P_SETPOS, []), + new Instruction(Opcode.LETI, [{ value: 60, size: 1 }, { value: 255, size: 4 }]), + new Instruction(Opcode.LETI, [{ value: 61, size: 1 }, { value: 0, size: 4 }]), + new Instruction(Opcode.LETI, [{ value: 62, size: 1 }, { value: 338, size: 4 }]), + new Instruction(Opcode.LETI, [{ value: 63, size: 1 }, { value: -43, size: 4 }]), + new Instruction(Opcode.ARG_PUSHL, [{ value: 1, size: 4 }]), + new Instruction(Opcode.ARG_PUSHR, [{ value: 60, size: 1 }]), + new Instruction(Opcode.P_SETPOS, []), + new Instruction(Opcode.LETI, [{ value: 60, size: 1 }, { value: 222, size: 4 }]), + new Instruction(Opcode.LETI, [{ value: 61, size: 1 }, { value: 0, size: 4 }]), + new Instruction(Opcode.LETI, [{ value: 62, size: 1 }, { value: 322, size: 4 }]), + new Instruction(Opcode.LETI, [{ value: 63, size: 1 }, { value: 25, size: 4 }]), + new Instruction(Opcode.ARG_PUSHL, [{ value: 2, size: 4 }]), + new Instruction(Opcode.ARG_PUSHR, [{ value: 60, size: 1 }]), + new Instruction(Opcode.P_SETPOS, []), + new Instruction(Opcode.LETI, [{ value: 60, size: 1 }, { value: 248, size: 4 }]), + new Instruction(Opcode.LETI, [{ value: 61, size: 1 }, { value: 0, size: 4 }]), + new Instruction(Opcode.LETI, [{ value: 62, size: 1 }, { value: 323, size: 4 }]), + new Instruction(Opcode.LETI, [{ value: 63, size: 1 }, { value: -20, size: 4 }]), + new Instruction(Opcode.ARG_PUSHL, [{ value: 3, size: 4 }]), + new Instruction(Opcode.ARG_PUSHR, [{ value: 60, size: 1 }]), + new Instruction(Opcode.P_SETPOS, []), + new Instruction(Opcode.RET, []), ], }, ],