
Show HN: My x86 emulator written in JavaScript - g3
http://copy.sh/v24/
======
staunch
This may as well be magic as far as I'm concerned. When I first saw
[http://bellard.org/jslinux/](http://bellard.org/jslinux/) I just about shat
myself. This is definitely another level of awesome. Well done.

~~~
ghayes
This really is extremely well done [and I'd like to see the unminified
source]. The next feature I'd want to see is networking support. I love the
idea to be able to run my entire dev setup in an emulated browser session
[e.g. ruby, rails, redis]. That would be a game changer on how I'd develop.

~~~
javanix
At 2000 kIPS you may have a few generations of javascript engines to go before
we get there.

That's not meant to take away from this project - it truly is amazing what can
be interpreted in the browser now.

~~~
tekacs
Just for reference's sake this does vary a fair bit by computer and browser -
mine never drops below ~8kIPS and runs mostly at ~15kIPS (and up to ~23kIPS).

Whilst this is nothing like the several orders of magnitude required for more
capable interactive behaviour, it _does_ make my load times noticeably faster
than those claimed on the page. :)

(I'm Chrome on Linux, i7 4th Gen, incidentally)

~~~
kuschku
I'm getting here > speed 1640kIPS on the old Nexus 7, don't you mean 8kkIPS?

(This value was the average while booting Linux)

~~~
tekacs
Absolutely so, yes. Thanks. :)

8 - 23 MIPS ain't so bad, right?

~~~
wnesensohn
For reference, that's about as fast as a Motorola 68030 @50MHz [1] which was
used in the AppleIIx, and while that was no slouch when it was released, you
wouldn't want to run a modern development environment on such a machine either
;)

[1]
[http://en.wikipedia.org/wiki/Motorola_68030](http://en.wikipedia.org/wiki/Motorola_68030)

------
bumbledraven
[https://news.ycombinator.com/item?id=6221724](https://news.ycombinator.com/item?id=6221724)

    
    
       g3 62 days ago | link | parent | on: Show HN: Virtual Machines in the Browser
       Just give me one more month, I'm almost there ...
    

The last month always takes at least 60 days. Strong work!

------
JoshTriplett
Very impressive.

Interesting bug: I can't seem to type '-', '=', '+', or '_' into the Linux
image. Missing '-' in particular makes it hard to run commands with options.

Elaborate workaround:

    
    
        /root% eval eq$(dmesg | grep 'e820 update' | sed 's/.*) \(.\).*/\1\1/')
        /root% echo $eq
        =
        /root% eval dash$eq$(uname bad 2>&1 | grep Usage: | sed 's/.*\[\(.\).*/\1/')
        /root% echo $dash
        -
        /root% uname ${dash}a
        Linux (none) 2.6.34.14 #44 Tue Oct 15 20:50:15 CEST 2013 i586 GNU/Linux 
    

The first command grabs an '=' from dmesg and sets "eq" to it (without typing
'='), and then the second command grabs a '-' from the usage message of uname
and sets "dash" to that (without typing '-'). The last shows how to use
${dash} in a command.

~~~
Sheepshow
This is the most soul-crushing category of bug, the kind which keeps me up all
night, drinking.

Build a skyscraper, and lock the keys inside for the ribbon cutting. Sorry pal
you lost your funding

Land on Mars, see an alien, but your camera is out of batteries and everybody
back on Earth thinks you're a quack.

Successfully perform open-heart surgery on a desert island, but muck up the
stitches and cause a scar. Your patient will hold it against you the rest of
his life (which you saved).

~~~
shurcooL
Luckily, he was able to come up with a workaround.

Here's a soul-crushing situation that doesn't have a workaround, as far as I
can tell.

You can play the original Deus Ex on OnLive. By default, it sets the fov to a
very low number. It's only possible to change it in the console (there is no
UI for it). But the console is disabled. However, you can get around that by
pressing T, which creates a mini console with "say " prepoulated. Press delete
to erase say, and type "fov 90". So close...

But they disabled the Enter key from working.

So you can get full access to the console, type the command that would fix the
FOV, but you're unable to execute it because Enter key does not get sent to
the game. You're completely helpless.

~~~
a1369209993
OnLive runs on OSX. gdb (i think) also runs on OSX. It should be possible to
isolate the callback used to handle keyboard input and call it with c=10. This
would take anywhere from hours to weeks of debugging though.

~~~
shurcooL
No, that won't work. Nothing you do client-side will help.

OnLive Client <-all input is transmitted-> OnLive Servers <-filter out Enter->
Deus Ex instance in a VM.

The enter key is filtered out on their servers. Unless you hack into their
servers and change that, there is nothing you can do on the client-side.
That's what makes you completely helpless.

~~~
a1369209993
Ah, my apologies, I thought the game was running locally. (This sort of
assholeness on the part of servers is basically why 'cloud computing' is such
a bad idea.)

~~~
shurcooL
I disagree that cloud computing is a bad idea because of this. It has
advantages and disadvantages. Not being able to hack around to make changes
you wish is a disadvantage, but having access to something you would not have
otherwise is a much bigger advantage.

------
hardwaresofton
Pretty awesome, I for one don't think the constant stream of "x, rewritten
completely in javascript" is tiring (this is not meant to be sarcastic).

[EDIT] - This post doesn't seem to say enough when I look back at it. Wanted
to add this:

Seeing posts like this really excites me (and inspires me) about the future of
web programming, and programming in general. Anyone that's excited about
programming has to get excited about abstraction, and it doesn't get much more
abstract that cross-coded/implemented virtualized systems like this. Even if
you hate javascript.

Every step people take in blurring lines between systems like this should be
exciting, given the large amount of abstraction that had to go into creating
something like this.

------
mambodog
If like this you might also be interested in my port of the PCE Emulator to
the browser: [http://jamesfriend.com.au/pce-
js/](http://jamesfriend.com.au/pce-js/)

At the moment I've only uploaded a demo of the Mac Plus emulator (classic 68k
mac) but I'll upload IBM PC and Atari ST demos soon also.

~~~
nwh
That's very nice too, though aren't you going to be running into some legal
issues by distributing their ROMs?

~~~
mambodog
Potentially, but I feel that the historical significance of these systems and
the value of making them available to a newer generation of creators outweighs
the technical infringement of copyright. It's basically abandonware, after
all.

I feel very strongly about the importance of learning from the past, and not
making the same mistakes over and over due to lack of historical perspective.
I was particularly inspired by Bret Victor's talk at the DBX conference[1].
That's what motivated me to make this available in the most accessible way
possible.

[1] [http://worrydream.com/dbx/](http://worrydream.com/dbx/)

~~~
Narishma
I don't know about the other games, but Wolfenstein 3D is definitely not
abandonware. You can still buy it on Steam, XBLA, PSN and other places.

~~~
Aardwolf
That image has the free shareware version of Wolf3D. It has only episode 1 and
is free to distribute to anyone.

------
cokernel_hacker
cute.

    
    
      /% cat /proc/cpuinfo                                                            
      processor       : 0                                                             
      vendor_id       : GenuineIntel                                                  
      cpu family      : 5                                                             
      model           : 1                                                             
      model name      : Pentium 60/66                                                 
      stepping        : 3                                                             
      cpu MHz         : 1.301                                                         
      cache size      : 256 KB                                                        
      fdiv_bug        : no                                                            
      hlt_bug         : no                                                            
      f00f_bug        : no                                                            
      coma_bug        : no                                                            
      fpu             : yes                                                           
      fpu_exception   : yes                                                           
      cpuid level     : 2                                                             
      wp              : yes                                                           
      flags           : fpu pse tsc cx8 pge cmov                                      
      bogomips        : 2.60                                                          
      clflush size    : 32                                                            
      cache_alignment : 32                                                            
      address sizes   : 32 bits physical, 32 bits virtual                             
      power management:
    

Heh, 1.3 MHz on a Pentium 60.

------
agilebyte

      125 kB compressed JS
      262 kB uncompressed JS
      9765 lines of uncompressed JS
    

Wow.

------
aray
Plan 9 iso [0] CD image fails

    
    
        Unimplemented: #GP handler
        Execution stopped
    

[0] [http://plan9.bell-labs.com/wiki/plan9/download/](http://plan9.bell-
labs.com/wiki/plan9/download/)

------
sramsay
Just when you thought "I've written an x in JavaScript" can't get any more
insane . . .

Still, this wins the Nobel Prize for awesome.

~~~
TeMPOraL
I'm still waiting for "Show HN: I built a self-modifying general AI in
JavaScript".

(@Eliezer, how's the work going? ;))

------
general_failure
Now and then I see a project which is soul crushing to me when I compare
myself with other programmers. This is one of them.

------
runn1ng
It actually boots on Chrome.

On Android.

Then it usually dies for low memory - and I can't enter anything at all
without keyboard (which doesn't pop up) - but still. The fact that I can boot
up a x86 emulator in javascript in browser on ARM mobile phone is crazy.

~~~
pcwalton
Works for me on Firefox for Android, no crashes yet.

------
mVChr
My second computer was an IBM XT 8086. That was the first time I played and
fell in love with Rogue. Every time I grab a copy of Rogue nowadays for
nostalgia's sake I'm left disappointed because I can never find the version of
Rogue that I played as a kid.

My friend, your emulator has that version of Rogue. The kid inside me thanks
you greatly.

------
Aardwolf
Would have been fun if it included some interface to execute assembler code on
it directly in some way (without booting an OS).

In any case, super awesome! Great work :)

EDIT: Whoa, the dos one has games on it! Can you make Wolf3D work? :)

~~~
Pitarou
I doubt it, but nethack might be worth a shot.

------
McGlockenshire
This is awesome.

You might want to consider re-ordering the font list in the console though.
Consolas isn't perfectly fixed-width apparently, and it made Rogue rather
puzzling to play.

~~~
sillysaurus2
Consoles isn't perfectly fixed width? That sucks. Till now it was my go-to
fixed width font.

I assumed something named _consol_ as would be a font suitable for consoles.

Which font do you like to use?

~~~
McGlockenshire
I use Consolas every day.

I'm on Linux, so that might also impact something.

Perhaps the line drawing characters are extra-small or something? Fire up
Rogue and try it out...

------
jordwalke
Two things:

1\. How can we help? How can I support you? 2\. Please open source this.

------
tectonic
This guy is awesome. Check out a Game of Life Turing Machine:
[http://copy.sh/life/?pattern=turingmachine](http://copy.sh/life/?pattern=turingmachine)

~~~
elwell
how do you use it to perform a calculation? or what should i be asking?

------
api
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.

~~~
g3
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.

~~~
dancecodes
its HTML5 and SSE?

~~~
dancecodes
Yes its HTML5. Saw header <!doctype html> ...

------
dbancajas
I want to write an emulator as a learning experience. Any tips how should I
start?

~~~
awy
I recently posted about emulating the NES with JavaScript.

[http://blog.alexanderdickson.com/javascript-nes-emulator-
par...](http://blog.alexanderdickson.com/javascript-nes-emulator-part-1)

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](http://blog.alexanderdickson.com/javascript-chip-8-emulator)

Good luck!

~~~
vinhboy
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.

~~~
awy
I have a heap on my plate right now but will hope to do part 2 before the end
of the year. Glad you enjoyed it.

------
s-macke
g3: Probably you have seen my emulator.
[http://s-macke.github.io/jor1k/](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 ;)

~~~
s-macke
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.

~~~
g3
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.

~~~
s-macke
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.

------
bcoates
Anyone know what format the floppies are expecting? It won't accept a DOS 6.22
install disk from MSDN, maybe it doesn't like DMF?

Also, swapping disks during the install might be an issue, I don't see a
button...

~~~
g3
It expects one of the standard formats (720k, 1440k or 2880k). I'll add
switching disks some time in the future.

~~~
WalterBright
It rejected my 360Kb images :-(

------
mvanotti
I'm trying to run a custom basic x86 kernel (it was an assignment for my
Computer Architecture course). But I can't get it to work =/. (This image
works with bochs and in a virtual machine without problems). It seems that it
can get to protected mode, enable interruptions, enable paging, but it fails
loading the tasks =/

This is the error that I'm getting:

Unimplemented: load system segment descriptor, type = 9 Execution stopped

Here's a screenshot:
[http://i.imgur.com/DdCt8jX.png](http://i.imgur.com/DdCt8jX.png)

------
mzs
I tried the freedos image, says something about 400kips and then down to 0.
Nothing ever shows. FF 17.0.9 ESR on 1386 freebsd 8.3

~~~
g3
I'm testing in Firefox 24. If you could tell me what the error console
outputs, I'll try to fix it.

~~~
mzs
Thanks, it's under the error tab:

ReferenceError: requestAnimationFrame is not defined
[http://copy.sh/v24/v86_all.js](http://copy.sh/v24/v86_all.js) Line: 239

~~~
mschuster91
Update to a newer Firefox. Your FF is dead old and doesnt support the new
HTML5 methods... and @author, maybe add a polyfill?

~~~
greglindahl
FF 24 is the latest stable. FF's docs say they added this function in FF 4.0,
which was several years ago. So it's a bit more complicated than you make it
out to be.

EDIT: I thought FF24 wasn't working, turns out I was confused between my Linux
desktop's and Mac laptop's FF versions. Sorry!

~~~
bzbarsky
It's actually not all that complicated.

Firefox 4 added mozRequestAnimationFrame.

Firefox 23 added the unprefixed version.

It's documented in the browser compatibility table at
[https://developer.mozilla.org/en-
US/docs/Web/API/window.requ...](https://developer.mozilla.org/en-
US/docs/Web/API/window.requestAnimationFrame) (note that "moz" next to the
4.0).

~~~
mzs
That must have done the trick, it starts now, thank you for your help.

------
pyrrhotech
Man, shit like this makes me feel dumb. How does this work?

------
dman
Is there a non minified version of the javascript emulator file that is
publicly available?

~~~
g3
I'll put it online soon. I haven't figured licensing out yet and need to write
some technical notes

~~~
ElDiablo666
I would like you to consider GPLv3+. Thanks and congrats on amazing work!

~~~
chrismorgan
In a case like this, the more important licensing question is that of the x86
instruction set; I do not know what the strict licensing situation would be
with that—it's quite possible (probable, actually) that this is technically
illegal.

For the _software_ part, why would you advocate GPLv3+ over permissive
licenses like MIT/BSD/Apache?

------
batuhanicoz
This is so cool!

I have one problem with it though, it doesn't seem to support my keyboard. For
example when I try "*", it writes "-".

I'm using a Turkish Q keyboard and Chromium on OS X Mavericks GM.

~~~
g3
It should be the US keyboard layout, because that's what the operating systems
in the emulator use.

~~~
Aardwolf
I know keyboard codes in web browsers are a nightmare, but, afaik it is
possible to get the intended ascii/unicode character code value of the key, so
the emulator could translate that to the US keyboard equivalent to fix this
issue.

------
senorsmile
I got a kernel panic trying to boot tinycore linux:

Decompressing Linux... Parsing ELF... done. Booting the kernel. init[1]:
segfault at b8e8e089 ip 08071929 sp bfb81b08 error 4 in busybox[8048000
+7c000] Kernel panic - not syncing: Attempted to kill init!
exitcode=0x0000000b

atkbd serio0: Spurious ACK on isa0060/serio0. Some program might be trying to
ac cess hardware directly.

~~~
g3
Both bugs are fixed now.

------
r4pha
This is beyond awesome! I'd love to read about your thought process while
writing it, I guess a lot of people (including myself) would learn a lot from
it. How long did it take to write?

~~~
g3
I got Freedos working about 2 years ago, but then stopped working on it. I
picked it up again earlier this year. Approximately 3 months of full time
work.

I'm considering writing some articles, just need to find some free time.

------
iso-8859-1
Here's a list of virtual machines in JavaScript:
[https://gist.github.com/ysangkok/5606032](https://gist.github.com/ysangkok/5606032)

------
etfb
When I first saw DOOM running on a bog-standard 386, I declared it to be utter
nonsense. I'm no fool! I know what's possible and what's impossible, and that
was clearly the latter. Sure, I knew it wasn't impossible, and in fact was
true and real and a testament to the brilliance of Carmack et al, but it was
still nonsense. Brilliant, astonishing nonsense.

I declare your x86 emulator similar nonsense, for all the same reasons. I take
my hat off to you. Well done indeed!

~~~
etfb
My gods. It runs on my phone. In a web browser. Now, if only I knew how to
make the onscreen keyboard pop up...

~~~
etfb
Hmmm... could you add a simple edit field, <input type="text">, that sent
anything typed in it directly to the emulated console? That would make it work
on a phone browser.

------
x0054
This is quite amazing. Could someone post a blog post on the details behind
how this works. I am not a JavaScrip programer, and this looks like black
magic to me at the moment.

------
urs2102
This is incredible! At this point, it's definitely JS magic, because I'm
struggling to fathom how this even exists.

------
dancecodes
Very interesting. Great job!

No xhr queries detected in firebug and firefox console. Its is done without
AJAX? How its working? Thanks.

~~~
dancecodes
wireshark says like "encrypted allert"

saw https packets

------
Tarang
I've been waiting ages for this ever since I saw jslinux. This is freaking
brilliant.

Looking at the source its been minified. How big is it before that? Are you
planning on going open source? Was kind of blown away to see the single js
file do all this. Would love to see the method's names to understand how it
works

------
hayksaakian
Cool, I tried the linux gui OS and games worked.

sudoku and snake worked really well, but pong seemed to graphically expensive

------
klepra
That's awesome, I quit! :)

------
agumonkey
waiting for docker.js

------
shurcooL
Has anyone had success running this on an iOS device? There are hints of it
working on my iPad mini under Chrome, but with Safari it gives a
"Unimplemented: #GP handler".

------
tharshan09
Could you give some tips or links on how to go about emulating an
architecture? I would like to know how to go about emulating an architecture
much less complicated like PIC.

------
jbobes
Very cool!

Btw, this is what I'm working on [http://cloud306.com](http://cloud306.com)
It's kind of similar, but not really.

------
seldo
Seems very like [http://bellard.org/jslinux/](http://bellard.org/jslinux/)
from a while back.

------
zerr
I know it is oversimplification, but in essence, isn't writing an emulator
just mundane following and reading specs? a lot of specs...

~~~
smackfu
Yes, following the specs will give you a correct emulator.

The trick is in writing a fast and accurate one.

------
bovermyer
...wow. Just, wow. You, my friend, are awesome.

------
buremba
If you add networking support to this amazing project, I think some crazy
development environment tools are waiting for us.

------
tnhu
This is a superb work! Beyond my imagination.

------
cattt
I can't sleep over the awesomeness of your emulator. I love you and happy
birthday <3

------
schmatz
I can just imagine the posts in a few years: "Look at my JavaScript GPU
emulator!"

------
ck2
The FreeDOS feels only half the speed of a TRS-80

This is jaw dropping. Imagine next generation javascript.

------
arjn
Love it and would like to learn more. Are there any docs you could make
available ?

------
zzx375
What else is there to say? Swung for downtown and knocked it into the ocean.

------
abeiz
Wow, very impressive! What are your plans for this? Any plans to open source?

~~~
g3
It will be open-source. I don't know how to deal with licensing yet.

~~~
Tobu
1\. Pick a license. You'll probably want something compatible with Qemu
(GPL2+).

2\. Ship a COPYING file, add a header to your files:
[https://github.com/osterman/copyright-
header](https://github.com/osterman/copyright-header)

------
swamy_g
Dude, this is Grade-A stuff.

------
eliben
Cool project. Can you elaborate on the difference between this and JSLinux?

------
haliphax
Very, very awesome. Kudos!

------
michaelmcmillan
I can't believe this

------
krallin
Doesn't quite exactly work on a non QWERTY keyboard : (

Still awesome, though!

------
mirsadm
The amazing thing is it works (slowly) on my Nexus 4. Great work!

------
LionRoar
A program listing as screensaver (KolibriOS). Now, that is cool.

------
malladye
how does it work?

~~~
samspenc
Yeah! Especially X - that's a pretty amazing X implementation!

~~~
tjdetwiler
It's not an X implementation, it's VESA emulation (disclaimer: this is a
guess).

~~~
g3
Good guess, that's correct

------
lxe
You should un-minify and open-source this.

------
constablebrew
I really want to make this run Node...

------
zenocon
no network interfaces :( boo. rm -rf or halt -f are fun.

this is great work. would love to see source un-minified.

~~~
g3
Networking is on the todo list. I couldn't host the traffic, though.

~~~
chii
i suppose you could try adding something to do the networking part via webrtc
as the channel?

~~~
Tobu
Nothing in the web platform lets you use raw (or TCP/UDP/etc) sockets. At most
you could do VPN-style networking and use a bridge to talk to the rest of the
internet; that bridge needs someone to host it.

~~~
chii
damn. at least i found [http://www.w3.org/TR/webrtc/#peer-to-peer-data-
api](http://www.w3.org/TR/webrtc/#peer-to-peer-data-api) which looks like its
a standard to allow for peer to peer data transfer.

------
chris_mahan
I'm totally impressed.

------
walke
Very cool! Great job!

------
dancecodes
now waiting release for support lxc containers :)

------
scosman
wow

------
elwell
github link?

------
_-_-_-
@g3 this is super-mega awesome. 3 questions:

1\. I know it is already available via the page, but would you please open-
source it so others could contribute?

2\. Thought I appreciate the apps being shown in the canvas in the resolution
they are supposed to use, a full-screen option would be incredible. That way I
could play space invaders the way it was meant to be played, in FreeDOS, in a
JS emulator, in Firefox, on a mac. (That's just so wrong, it's right.)

3\. Is that your real hair? (Sorry, just had to throw in a Real Genius quote.)

~~~
g3
Fullscreen is there and yes, it will be open source.

------
sambecket
this is beyond cool... logs off to think in some startup with this :)

