Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Emulating a BBC Microcomputer in Javascript (xania.org)
62 points by mattgodbolt on May 14, 2014 | hide | past | favorite | 19 comments


I remember going round a friends house and him loading up Elite onto a BBC B and my mind was blown.

An exceptional game in 32kb. Would be interesting to see if they get as far as running Elite.


Elite is the default image! Head to http://bbc.godbolt.org/ and hit shift-F12 to boot it :)


My MacBook Pro on Mavericks won't let me use Shift + F12 :(


You can change that. Goto Systems Preferences | Keyboard and then select the Shortcuts pane. Click Mission Control and then un-click the checkbox that binds F12 to Dashboard (which you probably do not use).


Thanks!

I do use dashboard (have my Selfoss RSS reader pinned to it) but only with my trackpad swipe-left :)


Bear in mind there would have been about 8k for the screen.


Being an American, I was never exposed to the BBC machines. I tried running the emulator and entering a small program; alas, I can't figure out how to enter the "=" key, so I had to give up. I couldn't find "+" either.

I found the hardest part of writing my own microcomputer emulator in javascript was keyboard mapping. Each browser does things in a somewhat different way, and then there is the inherent tradeoff between emulating the original keyboard layout faithfully vs using a logical layout (where pressing "=" on the PC keyboard results in a "=" event in the emulator).

As for the CPU emulation speed, indeed chrome doesn't optimize switch statements greater than 128 entries. I got around this by coding it as "if (opcode < 0x80) switch (opcode) { first 128 cases } else switch (opcode) { other 128 cases }

I had tried using a 256-way opcode dispatch table, which was great for chrome, but it hurt firefox performance (which is blazing with the 256-way switch). Having two 128-way switches was pretty good for both browsers.


Thanks!! I haven't really looked deeply into Firefox performance but I'll definitely give the two-way switch statement a go: thanks!


I'd love to see a messaging system set up to treat any of these JS Beebs currently running in any browser worldwide as though they're all on a single Econet.


Great stuff. I used a BBC Master up until 1999 as a serial terminal for a Sun machine. The thing was an electronics and experimenters dream: well documented, built in decent BASIC and assembler and ports galore plus if you blew it up, £5 was about all it cost to fix it (I.e. just get another one off eBay). Think they go for a lot more than that now.


This is really interesting to me. I actually started writing my own about three years ago, also called 'jsbeeb', in CoffeeScript. I didn't get around to finishing it, but the 6502 emulation worked, and it has just enough peripheral support to boot through enough of the OS to display the familiar banner: http://i.imgur.com/HjxV3ks.png


Here is an x86 emulator in Javascript running Linux 2.6.20 for those who might have missed it (2011): http://bellard.org/jslinux/

From the awesome Fabrice Bellard (qemu etc...)

Edit: Formatting, additional details


> Chrome’s v8 at least bails out its JIT process if a function is either too big, or if it has too many entries in the switch statement.

Is this true? Anyone have some sense of why?


I remember seeing in documentation somewhere that switch statements with more than 128 cases are not optimised in V8, that might be what OP is referring to; however, I've never seen a 128-case switch statement in production, nor have I seen a developer use that many cases in development, refactoring tends to happen earlier in my experience.


> switch statements with more than 128 cases are not optimised in V8

I recently saw this in Petka Antonov's "Optimization Killers"[1], though I've definitely seen it somewhere else as well, because I recall hearing that variables mixed with literals in a switch could trip up the optimizer.

[1] https://github.com/petkaantonov/bluebird/wiki/Optimization-k...


The error came from the profiler in v8: the main function was tagged as "Could not JIT - too many cases in switch statement" (or similar). I think it's a fair limitation; as you say, more than a few dozen is rare in "real" code - although one might argue this is a pretty common idiom for handling emulation of bytecodes.


Good read, although I now have a serious case of neck ache.

http://i.imgur.com/HaVWV4H.png


If you type in:

    *CAT 
at the prompt it will show an image listing.

    *Elite3 
will run the game. Star is mapped to ' normally. It's quite sad that I typed the above commands correctly without thinking when I loaded the page :)


I can't manage to type the star. FF29, Win, German keyboard.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: