From 369ba2ecedc77649eddc63a011025c02dd85706a Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Sun, 9 Sep 2012 20:03:27 +0100 Subject: [PATCH] More VM syscalls --- src/virtualmachine/Syscalls.cpp | 66 ++++++++++++++++++++------ src/virtualmachine/Syscalls.inl | 68 +++++---------------------- src/virtualmachine/VirtualMachine.cpp | 14 ++---- src/virtualmachine/VirtualMachine.h | 7 +++ 4 files changed, 75 insertions(+), 80 deletions(-) diff --git a/src/virtualmachine/Syscalls.cpp b/src/virtualmachine/Syscalls.cpp index 5358833ac..bc88fb24e 100644 --- a/src/virtualmachine/Syscalls.cpp +++ b/src/virtualmachine/Syscalls.cpp @@ -1,33 +1,71 @@ -#include "VirtualMachine.h" #include #include +#include +#include "VirtualMachine.h" +#include "simulation/Simulation.h" +#include "graphics/Renderer.h" namespace vm { - #define ARG(n) (Get(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(sin(ARG(0).float4)); + } - char *text; + TRAPDEF(cos) + { + Push(cos(ARG(0).float4)); + } - //crumb("SYSCALL Print [%d]\n", ARG(0)); - text = (char*)(ram) + ARG(0); - //crumb("PRINTING [%s]\n", text); - printf("%s", text); - return 0; + TRAPDEF(atan2) + { + Push(atan2(ARG(0).float4, ARG(1).float4)); + } + + TRAPDEF(sqrt) + { + Push(sqrt(ARG(0).float4)); + } + + TRAPDEF(floor) + { + Push(floor(ARG(0).float4)); + } + + TRAPDEF(ceil) + { + Push(ceil(ARG(0).float4)); } - TRAPDEF(Error) + TRAPDEF(print) + { + char *text; + text = (char*)(ram) + ARG(0).int4; + printf("%s", text); + } + + + 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(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 0da71d2c9..6338d119b 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 ff966ac8d..dfff84e78 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(); - 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 507250439..ab75e9601 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