views:

603

answers:

4

I'm looking to build a VM into a game and was wondering if anyone knew of any really simple VM's (I was thinking RISC/PIC was close to what I wanted) that are usually used for embedded projects such as controlling robots, motors, sensors, etc. My main concern is having to write a compiler/assembler if I roll my own. I'd be nice to use the tools that are already out there or in its simplest form just a C compiler that can compile for it :-p.

I really don't want to re-invent the wheel here but I also need thousands of these running around a virtual world so they have to be as simple and as fast as possible. As one person has already mentioned I also don't care about real world issues such a timing and buses and all that fun stuff. I think their virtual clocks will be limited to somthing quite slow; and eventually I'll probably have to look into native compiling to make them run even faster but for now I'm just putting together prototypes to get a general proof of concept.

As input, I'm planning on distance, light, material and touch sensors mounted around the cylindrical body (16, maybe 32 of them), then simply 2 motors for directional output to control a sort of wheel on each side. essentially the processing won't be too strenuous and the world will be simple enough so that the machine's don't have to throw lots of processing power at simple tasks.

In terms of memory, I'd like them to be able to store enough data to be left alone for a couple of days without intervention for building maps and gathering stats. I don't like 8bit would cut it for processing or memory but 16bit would definitely be a contender. 32 and 64bit would just be pushing it and there's no way they'll have any more than 1mb each of memory - probably closer to 256-512k. (Bill one said 640k would be enough so why can't I!!)

+1  A: 

if you want something rooted in the real world, one of the most-used embedded RISC microcontrollers is the PIC family. google gives several emulators, but i don't think the source is available for most.

another possibility is QEMU, which already emulates several ARM varieties.

and, of course, if you're not interested in emulating a real-world device, far easier and better performance would be to roll your own. with only what you need, and not getting into the mess of state flags, overflow bits, limited bus width, RAM timings, etc.

Javier
yes. I can sorta see everything I'd want it to do and like you say timing and flags and all that real world nonsense doesn't have to exist - main issue I'd like to adddres I guess is having a compiler ready built for it ;-p
widgisoft
then instead of emulating a CPU, use an embedded scripting language. Lua is a beautiful language, designed from the beginning to be embedded as an extension to a C aplication
Javier
I was really interested in lua but I just didn't get on with it's syntax enough to really want to do any more with it.
widgisoft
A: 

If you want simple, consider the Manchester Mark I. See page 15 of this PDF. The machine has 7 instructions. It takes about an hour to write an interpreter for it. Unfortunately, the instructions are pretty dang limited (which is why pretty much a full spec of the machine can fit on one page).

Javier's approach of rolling your own is very pragmatic. Designing and creating a tiny machine is a two day task, if that. I built a tiny VM for a project a few years ago and it took me two days to write the VM with a simple visual debugger.

Also - does it have to be RISC? You could choose, say, 68K for which there are open source emulators, and 68K was a well-understood target for gcc.

plinth
I'm not worried at all about building my own - I just don't want the haste of also writing a compiler. If I can base it as close as I can to something else that also has a c compiler then it should be a lot easier.
widgisoft
I'm also not 100% confident that it'll use text-based programming but for now it makes it easier also :-p
widgisoft
In that case, I'd definitely go 68K (first choice) or 6809 (http://www.oddchange.com/gcc6809/). Both are gcc targetable and are fairly friendly CPUs. MAME contains emulators for both. 6809 Limits you to a 64K address space without trickery.
plinth
+2  A: 

I wrote Wren for a friend who wanted a VM language running on an embedded controller with around 16K of RAM. (But it allows up to 64k per process in the code as written.) It includes a compiler for a dumb little programming language. It's all, uh, pretty basic and hasn't seen much use, but it is just what you described in your first paragraph.

Darius Bacon
Ummm...needs documentation. I'm suspicious of self links, but this seems responsive. Upvote.
dmckee
+1  A: 

The FORTH "virtual machine" is about as simple as they come. 16-bit address space (typically), 16-bit data words, two stacks, memory. Loeliger's "Threaded Interpretive Languages" tells you a lot about how to build a FORTH interpreter on a Z80.

John R. Strohm