summaryrefslogtreecommitdiff
path: root/src/pim/Machine.h
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-09-21 14:05:50 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-09-21 14:05:50 (GMT)
commit939a04d3c77bf9aa8d54e912f5e12817de51756c (patch)
tree750119bf74b8fbcb409eaf02d03877c00056613d /src/pim/Machine.h
parent6e44ebc358d1206c147f514225373da07b43c015 (diff)
downloadpowder-939a04d3c77bf9aa8d54e912f5e12817de51756c.zip
powder-939a04d3c77bf9aa8d54e912f5e12817de51756c.tar.gz
Testing new vm/language WIP
Diffstat (limited to 'src/pim/Machine.h')
-rw-r--r--src/pim/Machine.h88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/pim/Machine.h b/src/pim/Machine.h
new file mode 100644
index 0000000..dcaef92
--- /dev/null
+++ b/src/pim/Machine.h
@@ -0,0 +1,88 @@
+#pragma once
+
+#include <vector>
+#include <string>
+
+class Simulation;
+namespace pim
+{
+ union Word
+ {
+ int Integer;
+ float Decimal;
+
+ Word(int integer) : Integer(integer) {}
+ Word(float decimal) : Decimal(decimal) {}
+ Word() {}
+ };
+ struct Instruction
+ {
+ int Opcode;
+ Word Parameter;
+ };
+ class VirtualMachine
+ {
+
+ #define WORDSIZE 4
+
+ //#define OPDEF(name) void op##name(int parameter);
+ //#include "Opcodes.inl"
+ //#undef OPDEF
+
+ Simulation * sim;
+
+ Instruction * rom;
+ int romSize;
+ int romMask;
+
+ unsigned char * ram;
+ int ramSize;
+ int ramMask;
+
+ #define CSA(argument) (*((Word*)&ram[framePointer-argument]))
+ #define CS() (*((Word*)&ram[callStack]))
+ #define PS() (*((Word*)&ram[programStack]))
+
+ int programStack; //Points to the item on top of the Program Stack
+ int callStack; //Points to the item on top of the call stack
+ int framePointer; //Points to the bottom (first item) on the current frame of the call stack
+
+ //Instruction * instructions;
+
+ int programCounter;
+
+
+ public:
+ VirtualMachine(Simulation * sim);
+ int OpcodeArgSize(int opcode);
+ void LoadProgram(std::vector<unsigned char> programData);
+ void Run();
+ void Call(std::string entryPoint);
+ void Call(int entryPoint);
+ inline void PSPush(Word word)
+ {
+ programStack -= WORDSIZE;
+ PS() = word;
+ }
+
+ inline Word PSPop()
+ {
+ Word word = PS();
+ programStack += WORDSIZE;
+ return word;
+ }
+
+ inline void CSPush(Word word)
+ {
+ callStack -= WORDSIZE;
+ CS() = word;
+ }
+
+ inline Word CSPop()
+ {
+ Word word = CS();
+ callStack += WORDSIZE;
+ return word;
+ }
+ };
+} \ No newline at end of file