
Emulating a BBC Microcomputer in Javascript - mattgodbolt
http://xania.org/201405/jsbeeb-emulating-a-bbc-micro-in-javascript
======
awjr
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.

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

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

~~~
bobochan
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).

~~~
girvo
Thanks!

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

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

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

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

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

------
danellis
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](http://i.imgur.com/HjxV3ks.png)

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

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

Edit: Formatting, additional details

------
scotth
> 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?

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

~~~
XaspR8d
> 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...](https://github.com/petkaantonov/bluebird/wiki/Optimization-
killers#4-switch-case)

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

[http://i.imgur.com/HaVWV4H.png](http://i.imgur.com/HaVWV4H.png)

------
camperman
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 :)

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

