summaryrefslogtreecommitdiff
path: root/src/virtualmachine/Syscalls.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-11-17 19:44:09 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-11-17 19:44:09 (GMT)
commit058a2edd75debbd0297f92572316daa704bd379f (patch)
treead303f091f9a08b209b91eb34a9fcad996a3de69 /src/virtualmachine/Syscalls.cpp
parente3594aba9e05c6865d396418c028049cda92c2f3 (diff)
parent7a21ae192fe19868539956f3fe28e62b2c7c4429 (diff)
downloadpowder-058a2edd75debbd0297f92572316daa704bd379f.zip
powder-058a2edd75debbd0297f92572316daa704bd379f.tar.gz
Merge branch 'master' of github.com:FacialTurd/PowderToypp
Diffstat (limited to 'src/virtualmachine/Syscalls.cpp')
-rw-r--r--src/virtualmachine/Syscalls.cpp99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/virtualmachine/Syscalls.cpp b/src/virtualmachine/Syscalls.cpp
new file mode 100644
index 0000000..31b7dd4
--- /dev/null
+++ b/src/virtualmachine/Syscalls.cpp
@@ -0,0 +1,99 @@
+#include <cstdio>
+#include <cstdlib>
+#include <cmath>
+#include "VirtualMachine.h"
+#include "simulation/Simulation.h"
+#include "graphics/Renderer.h"
+
+namespace vm
+{
+ #define ARG(n) (Get(RP + ((2 + n) * sizeof(word))))
+
+ #define TRAPDEF(f) int VirtualMachine::trap##f()
+
+ TRAPDEF(sin)
+ {
+ Push<float4_t>(sin(ARG(0).float4));
+ return 0;
+ }
+
+ TRAPDEF(cos)
+ {
+ Push<float4_t>(cos(ARG(0).float4));
+ return 0;
+ }
+
+ TRAPDEF(atan2)
+ {
+ Push<float4_t>(atan2(ARG(0).float4, ARG(1).float4));
+ return 0;
+ }
+
+ TRAPDEF(sqrt)
+ {
+ Push<float4_t>(sqrt(ARG(0).float4));
+ return 0;
+ }
+
+ TRAPDEF(floor)
+ {
+ Push<float4_t>(floor(ARG(0).float4));
+ return 0;
+ }
+
+ TRAPDEF(ceil)
+ {
+ Push<float4_t>(ceil(ARG(0).float4));
+ return 0;
+ }
+
+
+ TRAPDEF(print)
+ {
+ char *text;
+ text = (char*)(ram) + ARG(0).int4;
+ printf("%s", text);
+ return 0;
+ }
+
+
+ TRAPDEF(error)
+ {
+ char *msg;
+ msg = (char*)(ram) + ARG(0).int4;
+ printf("%s", msg);
+ End();
+ return 0;
+ }
+
+
+ TRAPDEF(partCreate)
+ {
+ Push<int4_t>(sim->create_part(ARG(0).int4, ARG(1).int4, ARG(2).int4, ARG(3).int4));
+ return 0;
+ }
+
+ TRAPDEF(partChangeType)
+ {
+ sim->part_change_type(ARG(0).int4, ARG(1).int4, ARG(2).int4, ARG(3).int4);
+ return 0;
+ }
+
+ TRAPDEF(pmapData)
+ {
+ Push<int4_t>(sim->pmap[ARG(1).int4][ARG(0).int4]);
+ return 0;
+ }
+
+ TRAPDEF(deletePart)
+ {
+ sim->delete_part(ARG(0).int4, ARG(1).int4, ARG(2).int4);
+ return 0;
+ }
+
+ TRAPDEF(killPart)
+ {
+ sim->kill_part(ARG(0).int4);
+ return 0;
+ }
+}