I know this sounds like crazy pants, but I would actually use this in the real world if it were a NodeJS module.
Not for anything compute-intensive or serious, but for creating very secure very isolated VMs to run web apps or other services in an insecure environment. It could also be a great way to take a LAMP stack app and rapidly deploy it in certain cases. Again not for high performance, but for... I can think of a few things personally and I'm sure others can too. (Though honestly performance wouldn't be that bad...) Then add the ability to go back and forth between client and server, and virtual networking, and you might have a commercial "virtual DOS LAN with nodes in a browser as a service" startup. What for? Supporting legacy DOS crap: point of sale systems, etc. "Run your legacy DOS stuff in your browser with persistence in the cloud." You'd be surprised how much legacy DOS crap is out there.
The project is made with both browser and nodejs support in mind. There are still some issues to resolve, but I will definitely release a node version this year.
There are two sensible approaches: interpretation or dynamic translation.
If you want to write one as a learning experience for how the platform you're emulating works and how an emulator could work in principle, you probably want to write an interpreter: find out how the platform boots, build something to start reading and interpreting instructions, start adding emulated hardware devices, and you'll get an increasingly functional interpreter. For a start, you could ignore emulation of devices, and just write a CPU core that interprets instructions. If you want to learn how modern (but still non-hardware-assisted) emulation works, read about how qemu's dynamic code translator and other JIT compilers work, and build a CPU emulator based on that.
I'm not the OP but check out the book: "The Elements of Computing Systems: Building a Modern Computer from First Principles" It's quite comprehensive, not exactly about writing an emulator, but it should give you what you need.
I really like your tutorial. I been trying to learn assembly and your tutorial is really helping me put the big picture together. I hope you continue to work on making it better.
g3: Probably you have seen my emulator.
http://s-macke.github.io/jor1k/
It does more or less the same, but emulates a different CPU.
Your emulator is impressive and especially fast. I think it took a long time for you to optimize it.
I tried to start TinyCore, but it stops after decompressing the kernel. So still some work to do ;)
I saw the source and I have some tips for you:
Avoid the UInt32 Arrays and the >>> operator.
They could be transformed by the JIT compiler into doubles and slow everything down. This does not happen with the Int32 Arrays and the >> operator.
There is a plug-in called JIT-Inspector which give you this information. Unfortunately it does no longer work in Firefox 24. Firefox 22 was the last working version.
Additionally worker threads gave me an incredible speed boost in Firefox. The whole GUI stuff is then separated. Especially the costly canvas update.
Do you have any documentation to support the stuff about UInt32? The old Firefox JIT had some limitations like this but I'm not aware of anything like that in the current one (which has been shipping for multiple versions). Is it a v8 limitation similar to the 31-bit 'small integer' limitation?
Indeed at the moment I have nothing to support it. Half a year ago I had dozens of examples. Now it is more or less experience. In v8 I had two weeks ago some strange deoptimizations behavior in my code. It was almost gone after I exchanged two >>> operations. So in my experience it is still better to avoid such cases. No one knows really how the JIT compiler are working. What makes it worse. The behavior is changing every 6 weeks. And don't forget: Out there is more than Firefox and Chrome ;)
Hi s-macke. I've read the source code of your emulator before, good job.
I'm aware of the problem with big integers. I'll look into this more closely, thanks for your help. Regarding workers: I need some restructuring to get this working. I'll also need to figure out the fastest way to exchange the canvas buffer between the worker and the browser.
I did the copying by a for loop copying In32 Arrays which is an acceptable solution. It slows down the worker thread by 1-2% by using 10fps and a screen size of 640x400x32. I think the reason why I didn't used more advanced ArrayBuffer functions to do this was the IE. Probably this has changed.
The color transformations and so on can be done in the master GUI-thread.
Comments (190) 70 threads
Earlier commentsNot for anything compute-intensive or serious, but for creating very secure very isolated VMs to run web apps or other services in an insecure environment. It could also be a great way to take a LAMP stack app and rapidly deploy it in certain cases.
Again not for high performance, but for... I can think of a few things personally and I'm sure others can too.
(Though honestly performance wouldn't be that bad...)
Then add the ability to go back and forth between client and server, and virtual networking, and you might have a commercial "virtual DOS LAN with nodes in a browser as a service" startup. What for? Supporting legacy DOS crap: point of sale systems, etc. "Run your legacy DOS stuff in your browser with persistence in the cloud." You'd be surprised how much legacy DOS crap is out there.
If you want to write one as a learning experience for how the platform you're emulating works and how an emulator could work in principle, you probably want to write an interpreter: find out how the platform boots, build something to start reading and interpreting instructions, start adding emulated hardware devices, and you'll get an increasingly functional interpreter.
For a start, you could ignore emulation of devices, and just write a CPU core that interprets instructions.
If you want to learn how modern (but still non-hardware-assisted) emulation works, read about how qemu's dynamic code translator and other JIT compilers work, and build a CPU emulator based on that.
http://blog.alexanderdickson.com/javascript-nes-emulator-par...
Part 2 will be posted when it's done. :)
If you want to get something done much quicker, have a go at emulating the Chip-8 VM.
I also have a post, but it's less hand-holding than the first.
http://blog.alexanderdickson.com/javascript-chip-8-emulator
Good luck!
Your emulator is impressive and especially fast. I think it took a long time for you to optimize it. I tried to start TinyCore, but it stops after decompressing the kernel. So still some work to do ;)
Continue this thread — 3 replies
I'm aware of the problem with big integers. I'll look into this more closely, thanks for your help.
Regarding workers: I need some restructuring to get this working. I'll also need to figure out the fastest way to exchange the canvas buffer between the worker and the browser.
Also, swapping disks during the install might be an issue, I don't see a button...
All comments shown.
Couldn't load more comments. Check your connection and try again.