More VM syscalls

This commit is contained in:
Simon Robertshaw 2012-09-09 20:03:27 +01:00
parent b44ac1bb7d
commit 369ba2eced
4 changed files with 75 additions and 80 deletions

View File

@ -1,33 +1,71 @@
#include "VirtualMachine.h"
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <cmath>
#include "VirtualMachine.h"
#include "simulation/Simulation.h"
#include "graphics/Renderer.h"
namespace vm 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() #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));
}
//crumb("SYSCALL Print [%d]\n", ARG(0)); TRAPDEF(atan2)
text = (char*)(ram) + ARG(0); {
//crumb("PRINTING [%s]\n", text); Push<float4_t>(atan2(ARG(0).float4, ARG(1).float4));
printf("%s", text); }
return 0;
TRAPDEF(sqrt)
{
Push<float4_t>(sqrt(ARG(0).float4));
}
TRAPDEF(floor)
{
Push<float4_t>(floor(ARG(0).float4));
}
TRAPDEF(ceil)
{
Push<float4_t>(ceil(ARG(0).float4));
} }
TRAPDEF(Error) TRAPDEF(print)
{
char *text;
text = (char*)(ram) + ARG(0).int4;
printf("%s", text);
}
TRAPDEF(error)
{ {
char *msg; char *msg;
msg = (char*)(ram) + ARG(0).int4;
msg = (char*)(ram) + ARG(0);
printf("%s", msg); printf("%s", msg);
PC = romSize + 1; End();
return 0; }
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);
} }
} }

View File

@ -1,57 +1,11 @@
TRAPDEF(-1, Print) TRAPDEF(-104, sin)
TRAPDEF(-2, Error) TRAPDEF(-105, cos)
/*MAPTRAP(-3, Milliseconds) TRAPDEF(-106, atan2)
MAPTRAP(-4, Cvar_Register) TRAPDEF(-107, sqrt)
MAPTRAP(-5, Cvar_Update) TRAPDEF(-108, floor)
MAPTRAP(-6, Cvar_Set) TRAPDEF(-109, ceil)
MAPTRAP(-7, Cvar_VariableIntegerValue)
MAPTRAP(-8, Cvar_VariableStringBuffer) TRAPDEF(-110, error)
MAPTRAP(-9, Argc) TRAPDEF(-111, print)
MAPTRAP(-10, Argv) TRAPDEF(-112, partCreate)
MAPTRAP(-11, FS_FOpenFile) TRAPDEF(-113, partChangeType)
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)*/

View File

@ -22,7 +22,9 @@ namespace vm
RP(0), /* Return stack pointer. */ RP(0), /* Return stack pointer. */
PC(0), PC(0),
cm(0), cm(0),
cycles(0) cycles(0),
sim(NULL),
ren(NULL)
{ {
hunk = new char[hunkSize]; hunk = new char[hunkSize];
std::fill(hunk, hunk+hunkSize, 0); std::fill(hunk, hunk+hunkSize, 0);
@ -268,21 +270,15 @@ namespace vm
int VirtualMachine::syscall(int trap) int VirtualMachine::syscall(int trap)
{ {
int retval; PC = Pop<int4_t>();
word w;
retval = 0;
switch (trap) switch (trap)
{ {
#define TRAPDEF(n, f) case n: retval = trap##f(); break; #define TRAPDEF(n, f) case n: trap##f(); break;
#include "Syscalls.inl" #include "Syscalls.inl"
#undef TRAPDEF #undef TRAPDEF
} }
w = Pop();
PC = w.int4;
w.int4 = retval;
Push(w);
return 1; return 1;
} }
} }

View File

@ -2,6 +2,9 @@
#include "Exceptions.h" #include "Exceptions.h"
class Simulation;
class Renderer;
namespace vm namespace vm
{ {
@ -62,6 +65,7 @@ namespace vm
class VirtualMachine class VirtualMachine
{ {
bool bigEndian; /* host is big-endian (requires byte-swapping). */ bool bigEndian; /* host is big-endian (requires byte-swapping). */
/* Memory spaces. */ /* Memory spaces. */
@ -110,6 +114,9 @@ namespace vm
int opcodeParameterSize(int opcode); int opcodeParameterSize(int opcode);
int syscall(int programCounter); int syscall(int programCounter);
public: public:
Simulation * sim;
Renderer * ren;
#define OPDEF(n) int Op##n(word parameter); #define OPDEF(n) int Op##n(word parameter);
#include "Operations.inl" #include "Operations.inl"
#undef OPDEF #undef OPDEF