Skip to main content
GameDev.net gamedev.net
🔒 Locked

Virtual Machine Tutorials

Started by skap20 Jul 18, 2003 at 10:47 AM 10 replies 1.7k views
Original Post
skap20
skap20
I am planning to create a virtual machine and scripting language for my game. I ordered "Virtual Machine Design and Implementation" but it hasn''t arrived yet and I would like to read more than just one book. Does anyone know of any virtual machine tutorials online? -------------------- Nicholas Skapura skapura.2@wright.edu http://skap.8k.com AIM: skap35
Yanroy
Yanroy
I''ve dabbled in virtual machines without doing any kind of research or such. Learn a little ASM and then just write some kind of emulator with the same theory. Unless you''re going to get really complex, I don''t think you even need a book.

--------------------


You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming

You are unique. Just like everybody else.

"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

Yanroy@usa.com

--------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor
Nypyren
Nypyren
The virtual machine I wrote for my C parser performed operations on a stack like the RPN calculator stuff on HP-48G calculators. It was pretty neat.

[edited by - Nypyren on July 18, 2003 2:46:12 PM]
sBibi
sBibi
if you''ve already written emulators, it''s pretty much the same thing
if you haven''t, it could be interesting fo you to get information on these...
a nice thing to do with a virtual machine is to allow multiple scripts to run "simultaneously" (almost ), by having some sort of array or linked list of processors, each having their own stacks, registers, etc...

also one nice thing to do is to give the user the ability to write scripts either in the virtual machine''s assembly language, or in a higher-level, C-style language... and when you lad scripts, you pre-compile them to some kind of binary form your virtual processor will understand and execute faster than if it had to parse an ascii instruction set...
sBibi
sBibi
you can also define a bunch of commands (like console commands), and build your scripts out of that...
that way, you may execute the console''s command line contents in your virtual machine

and no, I don''t know any tutorials on virtual machines, sorry
have you tried google?
skap20
skap20
sBibi: That''s exactly how I want to do it. I will have an assembler to compile low level instructions for the virtual machine, but ultimately I''d like to write a compiler for it. Once I get to that stage, the compiler will just generate asm code and then call the VMs assembler. As far as multitasking, I am also considering that method but I have to read up on threads a bit more.

I just got my book "Virtual Machine Implementation and Design" yesterday! This isn''t very good thought because I haven''t done any of my schoolwork as a result, lol...It''s a great book by the way!

--------------------
Nicholas Skapura
skapura.2@wright.edu
http://skap.8k.com
AIM: skap35
evolutional
evolutional
How do you think you'd implement multitasking? Would you throw a new thread for each VM or would you have it executing a batch of instructions in a virtual execution stack/state and then move onto the next one, etc?

EDIT: There's some good VM tutorials on this site actually

[edited by - downgraded on July 19, 2003 4:41:39 PM]
thekid
thekid
Im currently about 60% done with a virtual machine and its companion object-oriented high-level language. It is called Iris. I have a site but its not been updated for a little so its kinda irrelevent ent at the moment. When i have the vm finalized and in a stable build i am intending on writing a tutorial, book, ect and releasing the code under a limiting liscence. I have learned a massive ammount while working on this project. To be honest the most influential sources have been: the Java virtual machine specification (free on suns site), the Unreal engine (kinda hard to get info on) and a few other things. I will keep you posted on when i get my site updated with some more info.
sBibi
sBibi
downgraded> a thread for each vm's process might not be too good actually... and it depends if you want to implements _threads_ OR _processes_, which are not quite the same
however, I think a thread for the vm is a good idea...

actually I handle all that in the virtual machine, using some kind of scheduler (don't know if it's the appropriate name), based on a per-frame max vm clock cycles...
it just loops through every process and executes its instructions until the maximum frame cycles are reached, then goes on to the next process, etc...
each process can set its max frame cycles, and can choose the type of cycle limit he wants, either the frame based type (for example 100 cycls per frame), or the time based type (10000 cycles per second).

the problem is that neither of those two are good...
that's mainly because my vm isn't in a thread, it executes each frame before the other parts of the engine (physics, graphics, etc..).

the first one can work really nicely without threads, BUT, if you lag down to 5fps, it will still be 100 cycles per frame, and even considering that there are wait and sleep functions that are time based and not frame based, the script's execution will still slow down because of the frame-based part :/
the other method could work perfectly in a thread though..
that's quite simple, works quite nicely, but definitely isn't adapted to all kind of vms :/


[edited by - sBibi on July 20, 2003 6:43:02 AM]
evolutional
evolutional
Unless you could dynamically adapt the number of cycles depending on the framerate, but that might lead to the system being unpredictable

I was thinking about how I''m going to implement my VM into my engine (to handle animation, AI, etc) and I think I''m going to throw the VM itself into a thread and have it act out a certain number of VM cycles on each script, before moving onto the next (similiar to your method I think). But then I''m wondering if I''ll have to create a message queue to throw events and such back to the main engine
skap20
skap20
quote:
Original post by downgraded
How do you think you''d implement multitasking? Would you throw a new thread for each VM or would you have it executing a batch of instructions in a virtual execution stack/state and then move onto the next one, etc?

EDIT: There''s some good VM tutorials on this site actually

[edited by - downgraded on July 19, 2003 4:41:39 PM]


Right now I plan to implement threads by giving each thread in the VM its own address space and set of registers. Each thread will be stored in a linked list and the VM will execute each one for a certain number of instructions, then move on to the next.

But honestly, I think I''ll have to wait until fall to implement multithreading because that''s when I have to take my operating systems class. It''s probably better to use the methods they teach me instead of coming up with my own.

--------------------
Nicholas Skapura
skapura.2@wright.edu
http://skap.8k.com
AIM: skap35

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.