5 ms·
Emulating a BBC Microcomputer in Javascript
- deleted 12y ago[deleted]
- scotth 12y ago> 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 12y agoI 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.
- mattgodbolt 12y agoThe 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.
- XaspR8d 12y ago> 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-killers#4-switch-case https://github.com/petkaantonov/bluebird/wiki/Optimization-k...
- awjr 12y agoI 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 12y agoElite is the default image! Head to http://bbc.godbolt.org/ http://bbc.godbolt.org/ and hit shift-F12 to boot it :)
- girvo 12y agoMy MacBook Pro on Mavericks won't let me use Shift + F12 :(
- bobochan 12y agoYou 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 12y agoThanks! I do use dashboard (have my Selfoss RSS reader pinned to it) but only with my trackpad swipe-left :)
- louthy 12y agoBear in mind there would have been about 8k for the screen.
- danellis 12y agoThis 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
- tasty_freeze 12y agoBeing 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 12y agoThanks!! I haven't really looked deeply into Firefox performance but I'll definitely give the two-way switch statement a go: thanks!
- lucaspiller 12y agoGood read, although I now have a serious case of neck ache. http://i.imgur.com/HaVWV4H.png http://i.imgur.com/HaVWV4H.png
- pling 12y agoGreat 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.
- camperman 12y agoIf 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 12y agoI can't manage to type the star. FF29, Win, German keyboard.
- bencollier49 12y agoI'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.
- HackinOut 12y agoHere 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