diff --git a/src/sfall_arrays.cc b/src/sfall_arrays.cc index f7529be..7bf4aad 100644 --- a/src/sfall_arrays.cc +++ b/src/sfall_arrays.cc @@ -12,11 +12,6 @@ using ArrayId = unsigned int; static ArrayId nextArrayID = 1; static ArrayId stackArrayId = 1; -using ArraysMap = std::unordered_map; - -ArraysMap arrays; -std::unordered_set temporaryArrays; - class SFallArrayElement : public ProgramValue { public: SFallArrayElement() @@ -48,6 +43,11 @@ public: std::vector data; }; +using ArraysMap = std::unordered_map; + +ArraysMap arrays; +std::unordered_set temporaryArrays; + ArrayId CreateArray(int len, uint32_t flags) { flags = (flags & ~1); // reset 1 bit @@ -61,13 +61,11 @@ ArrayId CreateArray(int len, uint32_t flags) len = ARRAY_MAX_SIZE; // safecheck } - SFallArray arr { len, flags }; - ArrayId array_id = nextArrayID++; stackArrayId = array_id; - arrays[array_id] = std::move(arr); + arrays.emplace(std::make_pair(array_id, SFallArray { len, flags })); return array_id; } diff --git a/src/sfall_opcodes.cc b/src/sfall_opcodes.cc index 1d4b89a..4a43704 100644 --- a/src/sfall_opcodes.cc +++ b/src/sfall_opcodes.cc @@ -11,6 +11,7 @@ #include "mouse.h" #include "object.h" #include "party_member.h" +#include "sfall_arrays.cc" #include "sfall_global_vars.h" #include "sfall_lists.h" #include "stat.h" @@ -296,6 +297,17 @@ static void opGetArrayKey(Program* program) programStackPushInteger(program, 33); } +// create_array +static void opCreateArray(Program* program) +{ + auto flags = programStackPopInteger(program); + auto len = programStackPopInteger(program); + + auto array_id = CreateArray(len, flags); + + programStackPushInteger(program, array_id); +} + // get_array static void opGetArray(Program* program) { @@ -365,6 +377,7 @@ void sfallOpcodesInit() interpreterRegisterOpcode(0x821D, opGetMouseY); interpreterRegisterOpcode(0x8220, opGetScreenWidth); interpreterRegisterOpcode(0x8221, opGetScreenHeight); + interpreterRegisterOpcode(0x822D, opCreateArray); interpreterRegisterOpcode(0x822F, opGetArray); interpreterRegisterOpcode(0x8231, opLenArray); interpreterRegisterOpcode(0x8237, opParseInt);