Adding arrays

This commit is contained in:
Vasilii Rogin 2023-04-20 00:58:30 +03:00
parent 0b533ce880
commit 9e579c393e
2 changed files with 19 additions and 8 deletions

View File

@ -12,11 +12,6 @@ using ArrayId = unsigned int;
static ArrayId nextArrayID = 1; static ArrayId nextArrayID = 1;
static ArrayId stackArrayId = 1; static ArrayId stackArrayId = 1;
using ArraysMap = std::unordered_map<ArrayId, SFallArray>;
ArraysMap arrays;
std::unordered_set<ArrayId> temporaryArrays;
class SFallArrayElement : public ProgramValue { class SFallArrayElement : public ProgramValue {
public: public:
SFallArrayElement() SFallArrayElement()
@ -48,6 +43,11 @@ public:
std::vector<SFallArrayElement> data; std::vector<SFallArrayElement> data;
}; };
using ArraysMap = std::unordered_map<ArrayId, SFallArray>;
ArraysMap arrays;
std::unordered_set<ArrayId> temporaryArrays;
ArrayId CreateArray(int len, uint32_t flags) ArrayId CreateArray(int len, uint32_t flags)
{ {
flags = (flags & ~1); // reset 1 bit flags = (flags & ~1); // reset 1 bit
@ -61,13 +61,11 @@ ArrayId CreateArray(int len, uint32_t flags)
len = ARRAY_MAX_SIZE; // safecheck len = ARRAY_MAX_SIZE; // safecheck
} }
SFallArray arr { len, flags };
ArrayId array_id = nextArrayID++; ArrayId array_id = nextArrayID++;
stackArrayId = array_id; stackArrayId = array_id;
arrays[array_id] = std::move(arr); arrays.emplace(std::make_pair(array_id, SFallArray { len, flags }));
return array_id; return array_id;
} }

View File

@ -11,6 +11,7 @@
#include "mouse.h" #include "mouse.h"
#include "object.h" #include "object.h"
#include "party_member.h" #include "party_member.h"
#include "sfall_arrays.cc"
#include "sfall_global_vars.h" #include "sfall_global_vars.h"
#include "sfall_lists.h" #include "sfall_lists.h"
#include "stat.h" #include "stat.h"
@ -296,6 +297,17 @@ static void opGetArrayKey(Program* program)
programStackPushInteger(program, 33); 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 // get_array
static void opGetArray(Program* program) static void opGetArray(Program* program)
{ {
@ -365,6 +377,7 @@ void sfallOpcodesInit()
interpreterRegisterOpcode(0x821D, opGetMouseY); interpreterRegisterOpcode(0x821D, opGetMouseY);
interpreterRegisterOpcode(0x8220, opGetScreenWidth); interpreterRegisterOpcode(0x8220, opGetScreenWidth);
interpreterRegisterOpcode(0x8221, opGetScreenHeight); interpreterRegisterOpcode(0x8221, opGetScreenHeight);
interpreterRegisterOpcode(0x822D, opCreateArray);
interpreterRegisterOpcode(0x822F, opGetArray); interpreterRegisterOpcode(0x822F, opGetArray);
interpreterRegisterOpcode(0x8231, opLenArray); interpreterRegisterOpcode(0x8231, opLenArray);
interpreterRegisterOpcode(0x8237, opParseInt); interpreterRegisterOpcode(0x8237, opParseInt);