Giter VIP home page Giter VIP logo

jsbeeb's Introduction

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

jsbeeb's People

Contributors

aidansean avatar biged avatar codeaholics avatar cread avatar dependabot[bot] avatar fortyseven avatar hexwab avatar kieranhj avatar mattgodbolt avatar murkle avatar ojwb avatar omgitsraven avatar pacman-ghost avatar pai1ie avatar partouf avatar regregex avatar ribbons avatar richtw1 avatar robsonjb1 avatar samskivington-poq avatar scarybeasts avatar stuaxo avatar tom-seddon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsbeeb's Issues

Local discs are broken

Get "undefined localDisc" error. Additionally there's an issue in BBC Elite where the NOP zp instruction gives an undefined variable c.

Improve tape loading sounds

Loading sounds use javacsript audio api waveforms instead of making their own: this limits the granularity of the sound changes and makes the loading noises less authentic

Ctrl-W closes the browser with no warning

Ideally we'd trap ctrl-W but that seems impossible. However, it's a fairly common thing to press when playing Exile, and it's disastrous: closing the browser!

Closing the browser with a game running should at least prompt an "Are you sure?" though it's going to be tricky to come up with non-annoying behaviour. Maybe only ask if there's been a keypress "recently"?

Another thought is to finally support persistent browser-local storage. Then upon going "back" the game could continue where it left off.

Sort out Master sideways RAM

Master should have sideways RAM mapped into banks 4, 5, 6 and 7. Currently it's using the same configuration as the BBC B (mapped into bank 13, blatting right over ADFS!).

Keys for Asteroids Deluxe don't work

[from the author! yay] : "The only trouble is the keys don't quite work properly:

Ctrl turns right
Caps Lock turns left continuously when enabled but I think holding Shift should turn left - I can't quite remember.
] is thrust but I'm not sure that's right

...I've only tried it in Safari and Chrome on a MacBook with UK keyboard layout though. Elite and Defender seem to work OK.."

problems with Basic tokeniser (one-line TETRIS)

It doesn't work (gives 'Bad Program') with this:
http://survex.com/~olly/rheolism/dsm_rheolism/

0d=d:IFdVDUd:a=POINT(32_POS,31-VPOS<<5):RETURNELSEMODE9:GCOL-9:CLG:OFF:d=9:REPEATVDU30:REPEATGOSUBFALSE:IFPOS=28VDUPOS,15,VPOS,24;11,26:IF0ELSEIFa=0PRINT:UNTIL0ELSEUNTILVPOS=25:v=ABSRNDMOD7:i=0:VDU4895;3:REPEATm=9-INKEY6MOD3:FORr=TRUETO1:t=rANDSGNt:IFt=rCOLOURv-15:VDUrEORm:i+=m=7AND9-6_r:IF0ELSEFORn=0TO11:d=n/3OR2EORd:GOSUBFALSE:IF1<<(n+i)MOD12AND975AND&C2590EC/8^vVDU2080_ABSr;:t+=a:IF0ELSENEXT,:VDU20:UNTILt_LOGm:UNTILVPOS=3

If you make it one byte shorter by removing the 3 from the end then it can be LISTed but I think that's a symptom of another problem somewhere as it doesn't work if you split it into multiple lines across the colons

Soft & hard reset loses local disc info

If you've picked a local disc and then do a soft or hard reset, you lose the disc image as the reset code reloads the FDC module, losing the disc.

(Reported via Chris Jordan)

CRTC R6 emulation bug

Setting CRTC R6 to 0 doesn't blank the entire screen:

?&FE00=6:?&FE01=0

B-Em has this bug too.

Support for (read-only) disks on arbitrary URLs

So I've just managed to image a floppy disc full of terrible software I wrote 25 years ago. I'd like to make it available online, and your emulator is the simplest and best way to do it.

...unfortunately I can't give people a link to the emulator which points at my disk image. I did try using a Google Drive image but this doesn't work on anonymous users (probably because it needs read-write access).

Ideally something a URL like this would be good: http://bbc.godbolt.org/?disc=http://...blah...

It doesn't sound too complicated as sth.js is already doing most of the necessary work. However, I do notice that sth.js seems to be going via a proxy on bbc.godbolt.org; is this because STH doesn't use CORS or is there more to it than that?

Sound in 'Snapper' wrong

Background sound is wrong while the ghosts are blue (after eating a pill) and the sound when you eat a ghost / cherry is wrong

Check all opcodes

Write some Beeb tests for each opcode and run each on various emulators (a la Rich's timings test). Compare and check jsbeeb against these (and maybe even a real BBC)

Video emulation too sensitive to sync width

(Reported by Richard Broahurst)

The video code is now so sensitive that you cannot use different h-sync pulse widths within the same screen without losing two thirds of the display.

Richard has a demo http://www.retrosoftware.co.uk/forum/viewtopic.php?f=19&t=903&hilit=rally#p6607 that allows the h-sync pulse settings to be altered while moving the map with the cursor keys. If you press a key on the top row (Q..U) it adjusts the odd (or even-can't remember) horizontal half character position and the middle row (A..H) it adjusts the other half char offset, the idea is to make them half a char apart on screen so that when scrolling the 31 and a half chars displayed doesn't move from side to side, but just scrolls smoothly. The bottom row (Z..M) moves the v-ruptured status block at the bottom to try to reduce the blurring/bouncing of the top of the 1UP, radar box and 2UP. The beeb default setting is achieved by pressing UAV, but smooth scrolling requires USB or USV (matching U or S) so that every other frame is either aligned or miss-aligned by half a character. On my most sensitive CRT, I can only use YAC (minimum control panel judder), USV or USB which both have slightly more judder on the first couple of scan lines on the 1UP, top of the radar and 2UP.

With any of the three settings mentioned above, there seems to be a copy of the second line of the control panel visible above the first line of the control panel. This may be a bug in Richard's code that doesn't show up on a real CRT, but it does seem strange.

Document autoboot parameter

Please add text to the help box to describe (or add a link to illustrate) the autoboot parameter. It's very useful!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.