summaryrefslogtreecommitdiff
path: root/src/virtualmachine/Syscalls.cpp
blob: 31b7dd465f36020fed1a5a942a29ef7ae6faf99f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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;
	}
}