• Stars
    star
    351
  • Rank 120,906 (Top 3 %)
  • Language
    JavaScript
  • License
    GNU General Publi...
  • Created about 13 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Javascript BBC micro emulator

jsbeeb tests

jsbeeb - Javascript BBC Micro emulator

A BBC Micro emulator in Javascript. Runs on Firefox, Chrome and Microsoft Edge. Emulates a 32K BBC B (with sideways RAM) and a 128K BBC Master. The BBC had a somewhat different-looking keyboard to a modern PC, and so it's useful to know some of the mappings:

  • BBC F0 is F10
  • BBC Break key is F12
  • BBC star is on " (if it doesn't work for you try shift-2)

To play right now, visit http://bbc.godbolt.org/. To load the default disc image (Elite in this case), press shift-F12 (which is shift-Break on the BBC).

Getting set up to run locally

jsbeeb needs to be built with webpack. If you're developing locally you'll need a recent node and then run npm install to install needed packages. node can be installed from https://nodejs.org/.

You can then run npm start to get a local webserver which will autoreload on changes in the code - visit http://localhost:8080/ and off you go.

jsbeeb uses node and webpack to afford me simple and standard web development tooling and third party library access without lots of painful copy/paste or wheel-reinventing, as well as the ability to better run tests, and "pack" up the site to make it smaller and faster to load when it's deployed to https://bbc.godbolt.org.

URL parameters

  • autoboot - fakes a shift break
  • disc1=XXX - loads disc XXX (from the discs/ directory) into drive 1
  • disc2=XXX - as above
  • disc1=local:YYY - creates a local disk YYY which will be kept in browser local storage
  • disc1=sth:ZZZ - loads disc ZZZ from the Stairway to Hell archive
  • tape=XXX - loads tape XXX (from the tapes/ directory)
  • tape=sth:ZZZ - loads tape ZZZ from the Stairway to Hell archive
  • patch=P - applies a memory patch P. See below.
  • loadBasic=X - loads 'X' (a resource on the webserver) as text, tokenises it and puts it in PAGE as if you'd typed it in to the emulator
  • embedBasic=X - loads 'X' (a URI-encoded string) as text, tokenises it and puts it in PAGE as if you'd typed it in to the emulator
  • autorun - types *TAPE then */ to run from tape. In conjunction with loadBasic it types RUN.
  • autochain - types *TAPE then CH."" to run from tape.
  • autotype - types whatever you put after. e.g. &autotype=PRINT"Matt is cool"%0a (return is URI escaped to %0a)
  • embed - Remove the margins around the screen, hide most navigation entries and make the page background transparent (intended for use when running within an iframe in a third-party site).
  • cpuMultiplier=X speeds up the CPU by a factor of X. May be fractional or below one to slow the CPU down. NB disc loads become unreliable with a too-slow CPU, and running too fast might cause the browser to hang.
  • sbLeft / sbRight / sbBottom - a URL to place left of, right of, or below the cub monitor. The left and right should be around 648 high and the bottom image should be around 896 wide. Left and right wider than 300 will run into problems on smaller screens; bottom taller than 100 or so similarly.
  • videoCyclesBatch - the number of video cycles to batch up befofre running the video emulation. Defaults to zero: anything higher leads to emulation inaccuracies. Useful for showing why accuracy is important, even if less efficient.
  • rom - load the given URL or path as an extra ROM. If a URL is provided, that URL must allow cross-site requests. Doesn't support the sth: pseudo URL unlike disc and tape, but if given a ZIP file will attempt to use the .rom file assumed to be within.

Patches

Patches can be applied by making a patch=P URL parameter. P is a sequence of semicolon separated patches of the form @XXXX,YYYY:ZZZZZ,... where the @XXXX specifies a PC address to breakpoint, the YYYY is the address to patch and the ZZZZ is the data to write at address YYYY. The @ part is optional, but is handy to ensure the code you want to patch has actually loaded. For example: patch=@31a6,0769:6e4c4d48465a which is a patch for the default Elite image. Once the PC has reached $31a6, the bytes at 0769 are replaced with 6e4c4d48465a.

Loading BASIC files from GitHub gists

Note that every update you make means you need to make a new raw link.

Things left to do

If you're looking to help:

  • Testing
  • Core
    • Save state ability
      • Once we have this I'd love to get some "reverse step" debugging support
    • Get the "boo" of the boot "boo-beep" working (disabled currently as the Javascript startup makes the sound dreadfully choppy on Chrome at least).
  • Save disc support
    • Local discs need to be made more workable and need an "export" feature
    • Multiple discs need a UI
  • git grep -i todo
  • Optimisation
    • While every attempt to make things fast has been made, I'm sure there's some more clever things that can be done without compromising emulation accuracy

Tests

For general correctness there are several tests in the tests directory, including:

  • Klaus Dormann's exhaustive test of all documented opcodes for 6502 and 65C12. This is brought in as a git submodule from a forked version of Klaus's original as it needed a few tweaks to get 65C12 working.
  • hoglet's Binary Coded Decimal tests.
  • A public domain Commodore 64 6502 test suite which tests every 6502 opcode (documented or otherwise) for every possible input and flags condition.

For timing correctness we have:

  • A timing test program written by Rich. It has been run on a real live BBC B and the results are in the directory. An SSD of the same tests is in the discs/ directory.
  • Some of Kevin Edwards' protection systems (stripped of the games themselves). These are extremely timing- and correctness-sensitive when it comes to the timers and interrupts of the BBC.
  • Some 65C12-specific read-modify-write tests written by Ed Spittles.

Tests can be run automatically if you have node installed - just run make and it'll ensure the relevant libraries are installed, then it'll run the tests. Please note it can take a while to run the whole test suite.

Thanks

jsbeeb was heavily based on Sarah Walker's C B-Em emulator -- thanks to her for her hard work and for open sourcing her code. B-em is now being maintained by a group of enthusiasts - thanks to them too!

Huge thanks to Richard Talbot-Watkins for his advice and help along the way in fathoming out the instruction timings, interrupt fun, video code rewrite and for being such a good pal all these many years!

Thanks to Michael Borcherds for his help; improving the keyboard layouts and handling in Javascript, reporting issues, chasing down game bugs and much more.

Thanks to David Banks (hoglet) for his help in testing the gnarly BCD flag behaviour on real live BBCs.

Cheers to Ed Spittles for testing various interrupt timing code on a real BBC.

Thanks to Chris Jordan for his thorough testing, bug reports, ideas and help.

A lot of the early development used the amazing Visual 6502 as reference for intra-instruction timings. Amazing stuff.

Special shout out the users of the 6502 Forums

More information

I've written a lot of how the innards work on my blog in the emulation section.
I gave a presentation on how it all fits together at work, and posted the video up on YouTube. I presented again at GOTO Chicago 2016, and I'm hoping they post the video up.

More Repositories

1

seasocks

Simple, small, C++ embeddable webserver with WebSockets support
C++
735
star
2

zindex

Create an index on a compressed text file
C
606
star
3

pt-three-ways

Path tracing, done three ways
C++
181
star
4

Miracle

JavaScript Sega Master System Emulator
JavaScript
112
star
5

reddog

Final resting place of the source to Argonaut Dreamcast game Red Dog Superior Firepower
C
107
star
6

agner

Reworking of Agner Fog's performance test programs for Linux
C++
97
star
7

xania

Xania MUD source
C++
50
star
8

owlet-editor

A modern BBC BASIC editor inspired by the BBC Micro Bot (https://bbcmicrobot.com)
JavaScript
49
star
9

path-tracer

A path tracer in rust
Rust
44
star
10

correct-by-construction

Correct by Construction : a presentation given at C++ on Sea 2020
HTML
20
star
11

cppcon-bits-between-bits

A presentation on how much stuff happens before your code even starts running
HTML
19
star
12

wolf-doom-quake

Slides on how Wolf and maybe one day other ID games worked
JavaScript
15
star
13

beebide

A web IDE for the BBC Micro
JavaScript
14
star
14

pt-three-ways-pres

Presentation for pt-three-ways - a CppCon 2019 presentation
HTML
14
star
15

cpponsea-2019

Slides for my 2019 presentation at C++ on Sea
HTML
13
star
16

verisnake

Snake in verilog
Python
12
star
17

memory-and-caches

Slides on memory and caches
HTML
12
star
18

cpu5things

5 things you never knew your CPU did for you
CSS
10
star
19

IRClient

1990s-era ARM assembly implementation of IRC. Preserved for posterity
Visual Basic
8
star
20

onslaught

An unreleased, unfinished BBC Micro game
7
star
21

cppp-fr-superpower

Slides for a talk at 2021 cppp.fr
HTML
7
star
22

performance-tuning

HTML
5
star
23

ce-behind-the-scenes

Slides for a "Behind the Scenes" presentation
HTML
5
star
24

conan-test

An example showing how I use CMake and Conan
CMake
5
star
25

ce-cppcon-talk

Slides from CppCon 2017
HTML
5
star
26

turing

JS implementation of turing machines
JavaScript
5
star
27

bbc-micro-emulation

Slides on emulating a BBC Micro in Javascript
HTML
5
star
28

frame

Hacking on a Raspberry Pi-based e-ink photo frame
C
4
star
29

miracle-sms-emulator

Presentation and supporting material for Miracle, a Sega Master System emulator
HTML
4
star
30

blog

My personal blog and other website files
Python
4
star
31

godbolt-terraform

Personal terraform setup for various AWS things
HCL
4
star
32

ce-lightning

Lightning talk about Compiler Explorer
CSS
3
star
33

whats-new-in-compiler-explorer-2023

Slides for a presentation on Compiler Explorer at C++ on Sea and CppNorth
HTML
3
star
34

yow-conversational-asm

Slides for a talk at YOW Tool Time
HTML
2
star
35

ccs-js

Cascading Configuration System (Javascript version)
JavaScript
2
star
36

goto-2018-cpp

Slides for my GOTO 2018 talk (presented 26th April 2018)
HTML
2
star
37

zindex-pres

HTML
2
star
38

dotfiles

Useful dotfiles (public)
Python
2
star
39

be6502

My take on Ben Eater's 6502 project
C++
1
star
40

pymu

Sketches
Python
1
star
41

seasocks-slides

Slides for a 5 min talk I gave on Seasocks at OS:OM
JavaScript
1
star
42

ninja-jump

HTML5 game written with my 7 and 5 year olds
JavaScript
1
star
43

ccs-conan

Conan package building for the CCS configuration library
Python
1
star