summaryrefslogtreecommitdiff
path: root/debug.h
diff options
context:
space:
mode:
authorFox Caminiti <fox@foxcam.net>2022-07-22 20:45:08 -0400
committerFox Caminiti <fox@foxcam.net>2022-07-22 20:45:08 -0400
commitfc8040d695644aaca4596adebeca4ea1369ef630 (patch)
treeaea6979da97c43df8f03f3a2d7b421ee71bef370 /debug.h
first
Diffstat (limited to 'debug.h')
-rw-r--r--debug.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/debug.h b/debug.h
new file mode 100644
index 0000000..6128627
--- /dev/null
+++ b/debug.h
@@ -0,0 +1,78 @@
+#if DEBUG
+
+global_variable int32 *debugnull = NULL;
+#define Assert(Expression) if(!(Expression)) {*debugnull = 21;}
+
+enum valtype {
+ d_float,
+ d_uint,
+ d_int
+};
+
+union debugval {
+ real32 f;
+ uint32 u;
+ int32 i;
+};
+
+struct project_debug
+{
+ uint32 Markers[8];
+ uint32 MarkerIndex = 0;
+ uint64 CycleCount[8];
+ uint64 EndCycleCount[8];
+ uint64 ExecutionAmount[8];
+
+ valtype DebugPropertyType[6];
+ debugval Val[6];
+ char *String[6];
+ uint32 WatchedProperties;
+ bool32 ToggleWindow;
+};
+
+global_variable project_debug Debug;
+
+#if ARM
+#define DEBUG_CycleCountStart(ID)
+#define DEBUG_CycleCountEnd(ID)
+#else
+#define DEBUG_CycleCountStart(ID) Debug.CycleCount[ID] = __rdtsc();
+#define DEBUG_CycleCountEnd(ID) Debug.EndCycleCount[ID] += __rdtsc() - Debug.CycleCount[ID]; Debug.ExecutionAmount[ID]++;
+#endif
+
+internal void
+DebugWatchVar(char *Name, void *Address, valtype Type) {
+ uint32 i = Debug.WatchedProperties;
+ Debug.String[i] = Name;
+ if (Type == d_float)
+ Debug.Val[i].f = *(real32 *)Address;
+ if (Type == d_uint)
+ Debug.Val[i].u = *(uint32 *)Address;
+ if (Type == d_int)
+ Debug.Val[i].i = *(int32 *)Address;
+ Debug.DebugPropertyType[i] = Type;
+ Debug.WatchedProperties++;
+}
+
+#else
+
+#define Assert(Expression)
+
+enum valtype {
+};
+
+union debugval {
+};
+
+struct project_debug
+{
+};
+
+#define DEBUG_CycleCountStart(ID)
+#define DEBUG_CycleCountEnd(ID)
+
+internal void
+DebugWatchVar(char *Name, void *Address, valtype Type) {
+}
+#endif
+