Raised This Month: $ Target: $400
 0% 

Making a Virtual Machine with SourcePawn


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
nergal
Veteran Member
Join Date: Apr 2012
Old 08-05-2016 , 20:57   Making a Virtual Machine with SourcePawn
Reply With Quote #1

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!
__________________

Last edited by nergal; 08-05-2016 at 22:19.
nergal is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 08-05-2016 , 21:04   Re: Making a Virtual Machine with SP
Reply With Quote #2

So... a VM on top of another VM?
Potato Uno is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 08-05-2016 , 21:13   Re: Making a Virtual Machine with SP
Reply With Quote #3

Quote:
Originally Posted by Potato Uno View Post
So... a VM on top of another VM?
yes lmao. Also why not?
__________________

Last edited by nergal; 08-05-2016 at 21:14.
nergal is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 08-12-2016 , 18:38   Re: Making a Virtual Machine with SourcePawn
Reply With Quote #4

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 is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 08-26-2016 , 13:31   Re: Making a Virtual Machine with SourcePawn
Reply With Quote #5

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
__________________

Last edited by nergal; 08-26-2016 at 13:32.
nergal is offline
Chief149
Member
Join Date: Sep 2010
Old 08-26-2016 , 14:35   Re: Making a Virtual Machine with SourcePawn
Reply With Quote #6

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.
Chief149 is offline
thecount
Veteran Member
Join Date: Jul 2013
Old 08-26-2016 , 16:00   Re: Making a Virtual Machine with SourcePawn
Reply With Quote #7

Quote:
Originally Posted by Chief149 View Post
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.

Last edited by thecount; 08-26-2016 at 16:00.
thecount is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 08-26-2016 , 17:28   Re: Making a Virtual Machine with SourcePawn
Reply With Quote #8

Quote:
Originally Posted by Chief149 View Post
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?
__________________

Last edited by nergal; 08-26-2016 at 18:26.
nergal is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 12-30-2016 , 12:49   Re: Making a Virtual Machine with SourcePawn
Reply With Quote #9

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/
__________________
nergal is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:42.


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