AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Making a Virtual Machine with SourcePawn (https://forums.alliedmods.net/showthread.php?t=286014)

nergal 08-05-2016 20:57

Making a Virtual Machine with SourcePawn
 
https://bitbucket.org/assyrian/tf2-building-vm/src/

Hello to whoever reads this, I'm making a stack-based VM straight in sourcepawn.

The entire purpose of this plugin is to create programmable engineer buildings for TF2 where knowledgeable or interested players could make their buildings do more than what they currently do.

the Current Opcode list is...

PHP Code:

load loads a constant into memory
add 
adds two stack items
sub 
subs two stack items
mul 
multiplies two stack items
div 
divides two stack items
jmp 
jumps to a portion of the instruction list
print - 
prints the data at the current stack pointer
pop 
removes the first data at the stack pointer
inc 
increments an item in memory
dec 
decrements an item in memory
brt 
same as jmp but conditional if the stack item is true
brf 
same as brt but branches if the stack item is false
eq 
checks if two stack items are equal
less 
checks if the secondary stack item is less than the first stack item
great 
checks if the secondary stack item is greater than the first stack item
AND - does bitwise AND operation between two stack items
OR - does bitwise OR operation between two stack items
XOR - does bitwise XOR operation between two stack items
NOT 
does bitwise complement operation on the first stack item the stack pointer lists 

what I would hope to do in the future is to define variables/identifiers as well as do a call stack so I can implement subroutines!

Potato Uno 08-05-2016 21:04

Re: Making a Virtual Machine with SP
 
So... a VM on top of another VM?

nergal 08-05-2016 21:13

Re: Making a Virtual Machine with SP
 
Quote:

Originally Posted by Potato Uno (Post 2442615)
So... a VM on top of another VM?

yes lmao. Also why not?

nergal 08-12-2016 18:38

Re: Making a Virtual Machine with SourcePawn
 
I forgot that there's a Stack datatype in the sourcemod lib which I should probably use to replace the stack in this MetaVM. I should also add registers to this VM and use the stack for function calls.

nergal 08-26-2016 13:31

Re: Making a Virtual Machine with SourcePawn
 
there we go, upgraded the whole plugin to use data structures!

I used stringmap to make an opcode table, used the arraylist struct to hold all the tokens for the instruction set, and used arraystack to replace the int array stack.

https://bitbucket.org/assyrian/tf2-b...ng/?at=default

Chief149 08-26-2016 14:35

Re: Making a Virtual Machine with SourcePawn
 
You should make this VM capable of running Windows. Then put Windows on it, and then load a source engine game on THAT.

Great way to make the universe implode on itself.

thecount 08-26-2016 16:00

Re: Making a Virtual Machine with SourcePawn
 
Quote:

Originally Posted by Chief149 (Post 2448478)
You should make this VM capable of running Windows. Then put Windows on it, and then load a source engine game on THAT.

And then run the VM on the VM's own source engine. Just in case.

nergal 08-26-2016 17:28

Re: Making a Virtual Machine with SourcePawn
 
Quote:

Originally Posted by Chief149 (Post 2448478)
You should make this VM capable of running Windows. Then put Windows on it, and then load a source engine game on THAT.

Great way to make the universe implode on itself.

lol the whole point of this was to make programmable sentry guns xD

I mean, how else can u make the engineer buildings do custom things?

nergal 12-30-2016 12:49

Re: Making a Virtual Machine with SourcePawn
 
new update to this thing!

I changed the instructions to be a little bit more similar to x86 for familiarity.

I made a cheap little tokenizer to actually split up text in a way that you can format better and still have it.

the tokenizer can even tokenize the 0x0 style Hexadecimal values.

tokenizer ignores spaces, tabs, commas, new lines, and carriage return.

most importantly, this VM isn't just a stack machine either, it has both a useable stack and 8 registers

the new instruction set is...
PHP Code:

"halt"
"mov"
"push"
"pop"
"add"
"sub"
"mul"
"div"
"inc"
"dec"
"neg"
"and"
"or"
"xor"
"not"
"jmp"
"call"
"ret"
    
"grt"
"less"
"eql"
"grteq"
"lesseq" 

The useable register's are.
PHP Code:

// Set registers
"eax"
"ebx"
"ecx"
"edx"
"esi"
"edi"
"ebp"
"esp" 
// when increment the stack, this increases by 4. decreases everytime you pop the stack. 

example code
PHP Code:

mov eax 10dec eaxgrt eax 0 3halt 

C equivalent code
PHP Code:

int i=10;
--
i;
while (
0)
   --
i

try it out!

https://bitbucket.org/assyrian/tf2-building-vm/src/


All times are GMT -4. The time now is 22:33.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.