summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-09-09 19:03:27 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-09-09 19:03:27 (GMT)
commit369ba2ecedc77649eddc63a011025c02dd85706a (patch)
treece4b5db08f07c26f6fcfb469cf32f7d2f266a024 /src
parentb44ac1bb7dbe59170251dc6d38421c45e00bea9f (diff)
downloadpowder-369ba2ecedc77649eddc63a011025c02dd85706a.zip
powder-369ba2ecedc77649eddc63a011025c02dd85706a.tar.gz
More VM syscalls
Diffstat (limited to 'src')
-rw-r--r--src/virtualmachine/Syscalls.cpp64
-rw-r--r--src/virtualmachine/Syscalls.inl68
-rw-r--r--src/virtualmachine/VirtualMachine.cpp14
-rw-r--r--src/virtualmachine/VirtualMachine.h7
4 files changed, 74 insertions, 79 deletions
diff --git a/src/virtualmachine/Syscalls.cpp b/src/virtualmachine/Syscalls.cpp
index 5358833..bc88fb2 100644
--- a/src/virtualmachine/Syscalls.cpp
+++ b/src/virtualmachine/Syscalls.cpp
@@ -1,33 +1,71 @@
-#include "VirtualMachine.h"
#include <cstdio>
#include <cstdlib>
+#include <cmath>
+#include "VirtualMachine.h"
+#include "simulation/Simulation.h"
+#include "graphics/Renderer.h"
namespace vm
{
- #define ARG(n) (Get<int4_t>(RP + ((2 + n) * sizeof(word))))
+ #define ARG(n) (Get(RP + ((2 + n) * sizeof(word))))
#define TRAPDEF(f) int VirtualMachine::trap##f()
- TRAPDEF(Print)
+ TRAPDEF(sin)
{
+ Push<float4_t>(sin(ARG(0).float4));
+ }
- char *text;
+ TRAPDEF(cos)
+ {
+ Push<float4_t>(cos(ARG(0).float4));
+ }
+
+ TRAPDEF(atan2)
+ {
+ Push<float4_t>(atan2(ARG(0).float4, ARG(1).float4));
+ }
+
+ TRAPDEF(sqrt)
+ {
+ Push<float4_t>(sqrt(ARG(0).float4));
+ }
+
+ TRAPDEF(floor)
+ {
+ Push<float4_t>(floor(ARG(0).float4));
+ }
- //crumb("SYSCALL Print [%d]\n", ARG(0));
- text = (char*)(ram) + ARG(0);
- //crumb("PRINTING [%s]\n", text);
+ TRAPDEF(ceil)
+ {
+ Push<float4_t>(ceil(ARG(0).float4));
+ }
+
+
+ TRAPDEF(print)
+ {
+ char *text;
+ text = (char*)(ram) + ARG(0).int4;
printf("%s", text);
- return 0;
}
- TRAPDEF(Error)
+ TRAPDEF(error)
{
char *msg;
-
- msg = (char*)(ram) + ARG(0);
+ msg = (char*)(ram) + ARG(0).int4;
printf("%s", msg);
- PC = romSize + 1;
- return 0;
+ End();
+ }
+
+
+ TRAPDEF(partCreate)
+ {
+ Push<int4_t>(sim->create_part(ARG(0).int4, ARG(1).int4, ARG(2).int4, ARG(3).int4));
+ }
+
+ TRAPDEF(partChangeType)
+ {
+ sim->part_change_type(ARG(0).int4, ARG(1).int4, ARG(2).int4, ARG(3).int4);
}
} \ No newline at end of file
diff --git a/src/virtualmachine/Syscalls.inl b/src/virtualmachine/Syscalls.inl
index 0da71d2..6338d11 100644
--- a/src/virtualmachine/Syscalls.inl
+++ b/src/virtualmachine/Syscalls.inl
@@ -1,57 +1,11 @@
-TRAPDEF(-1, Print)
-TRAPDEF(-2, Error)
-/*MAPTRAP(-3, Milliseconds)
- MAPTRAP(-4, Cvar_Register)
- MAPTRAP(-5, Cvar_Update)
- MAPTRAP(-6, Cvar_Set)
- MAPTRAP(-7, Cvar_VariableIntegerValue)
- MAPTRAP(-8, Cvar_VariableStringBuffer)
- MAPTRAP(-9, Argc)
- MAPTRAP(-10, Argv)
- MAPTRAP(-11, FS_FOpenFile)
- MAPTRAP(-12, FS_Read)
- MAPTRAP(-13, FS_Write)
- MAPTRAP(-14, FS_FCloseFile)
- MAPTRAP(-15, SendConsoleCommand)
- MAPTRAP(-16, LocateGameData)
- MAPTRAP(-17, DropClient)
- MAPTRAP(-18, SendServerCommand)
- MAPTRAP(-19, SetConfigstring)
- MAPTRAP(-20, GetConfigstring)
- MAPTRAP(-21, GetUserinfo)
- MAPTRAP(-22, SetUserinfo)
- MAPTRAP(-23, GetServerinfo)
- MAPTRAP(-24, SetBrushModel)
- MAPTRAP(-25, Trace)
- MAPTRAP(-26, PointContents)
- MAPTRAP(-27, InPVS)
- MAPTRAP(-28, InPVSIgnorePortals)
- MAPTRAP(-29, AdjustAreaPortalState)
- MAPTRAP(-30, AreasConnected)
- MAPTRAP(-31, LinkEntity)
- MAPTRAP(-32, UnlinkEntity)
- MAPTRAP(-33, EntitiesInBox)
- MAPTRAP(-34, EntityContact)
- MAPTRAP(-35, BotAllocateClient)
- MAPTRAP(-36, BotFreeClient)
- MAPTRAP(-37, GetUsercmd)
- MAPTRAP(-38, GetEntityToken)
- MAPTRAP(-39, FS_GetFileList)
- MAPTRAP(-40, DebugPolygonCreate)
- MAPTRAP(-41, DebugPolygonDelete)
- MAPTRAP(-42, RealTime)
- MAPTRAP(-43, SnapVector)
- MAPTRAP(-44, TraceCapsule)
- MAPTRAP(-45, EntityContactCapsule)
- MAPTRAP(-46, FS_Seek)
- MAPTRAP(-101, memset)
- MAPTRAP(-102, memcpy)
- MAPTRAP(-103, strncpy)
- MAPTRAP(-104, sin)
- MAPTRAP(-105, cos)
- MAPTRAP(-106, atan2)
- MAPTRAP(-107, sqrt)
- MAPTRAP(-111, floor)
- MAPTRAP(-112, ceil)
- MAPTRAP(-113, testPrintInt)
- MAPTRAP(-114, testPrintFloat)*/ \ No newline at end of file
+TRAPDEF(-104, sin)
+TRAPDEF(-105, cos)
+TRAPDEF(-106, atan2)
+TRAPDEF(-107, sqrt)
+TRAPDEF(-108, floor)
+TRAPDEF(-109, ceil)
+
+TRAPDEF(-110, error)
+TRAPDEF(-111, print)
+TRAPDEF(-112, partCreate)
+TRAPDEF(-113, partChangeType) \ No newline at end of file
diff --git a/src/virtualmachine/VirtualMachine.cpp b/src/virtualmachine/VirtualMachine.cpp
index ff966ac..dfff84e 100644
--- a/src/virtualmachine/VirtualMachine.cpp
+++ b/src/virtualmachine/VirtualMachine.cpp
@@ -22,7 +22,9 @@ namespace vm
RP(0), /* Return stack pointer. */
PC(0),
cm(0),
- cycles(0)
+ cycles(0),
+ sim(NULL),
+ ren(NULL)
{
hunk = new char[hunkSize];
std::fill(hunk, hunk+hunkSize, 0);
@@ -268,21 +270,15 @@ namespace vm
int VirtualMachine::syscall(int trap)
{
- int retval;
- word w;
+ PC = Pop<int4_t>();
- retval = 0;
switch (trap)
{
- #define TRAPDEF(n, f) case n: retval = trap##f(); break;
+ #define TRAPDEF(n, f) case n: trap##f(); break;
#include "Syscalls.inl"
#undef TRAPDEF
}
- w = Pop();
- PC = w.int4;
- w.int4 = retval;
- Push(w);
return 1;
}
} \ No newline at end of file
diff --git a/src/virtualmachine/VirtualMachine.h b/src/virtualmachine/VirtualMachine.h
index 5072504..ab75e96 100644
--- a/src/virtualmachine/VirtualMachine.h
+++ b/src/virtualmachine/VirtualMachine.h
@@ -2,6 +2,9 @@
#include "Exceptions.h"
+class Simulation;
+class Renderer;
+
namespace vm
{
@@ -62,6 +65,7 @@ namespace vm
class VirtualMachine
{
+
bool bigEndian; /* host is big-endian (requires byte-swapping). */
/* Memory spaces. */
@@ -110,6 +114,9 @@ namespace vm
int opcodeParameterSize(int opcode);
int syscall(int programCounter);
public:
+ Simulation * sim;
+ Renderer * ren;
+
#define OPDEF(n) int Op##n(word parameter);
#include "Operations.inl"
#undef OPDEF