summaryrefslogtreecommitdiff
path: root/src/var.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/var.c')
-rw-r--r--src/var.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/var.c b/src/var.c
new file mode 100644
index 000000000..ee9604385
--- /dev/null
+++ b/src/var.c
@@ -0,0 +1,38 @@
+#include "global.h"
+
+extern u16 gVars[];
+
+extern u16 *gSpecialVars[];
+
+u16 *GetVarPointer(u16 id)
+{
+ if (id < 0x4000)
+ return NULL;
+
+ if ((s16)id >= 0)
+ return &gVars[id];
+
+ return gSpecialVars[id - 0x8000];
+}
+
+u16 VarGet(u16 id)
+{
+ u16 *ptr = GetVarPointer(id);
+ if (!ptr)
+ return id;
+ return *ptr;
+}
+
+bool8 VarSet(u16 id, u16 value)
+{
+ u16 *ptr = GetVarPointer(id);
+ if (!ptr)
+ return FALSE;
+ *ptr = value;
+ return TRUE;
+}
+
+u8 VarGetFieldObjectGraphicsId(u8 id)
+{
+ return VarGet(0x4010 + id);
+}