From b52494be04c2fd233db5b81bc53ef2f653ac7ff3 Mon Sep 17 00:00:00 2001 From: YamaArashi Date: Mon, 17 Oct 2016 23:11:09 -0700 Subject: var.c --- src/var.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/var.c (limited to 'src') 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); +} -- cgit v1.2.3