(Translated by https://www.hiragana.jp/)
BBC Micro on an FPGA | mikestirling.co.uk
The Wayback Machine - https://web.archive.org/web/20121220040826/http://mikestirling.co.uk:80/bbc-micro-on-an-fpga/

BBC Micro on an FPGA

Introduction

Chuckie Egg running on BBC FPGA

Chuckie Egg running on BBC FPGA

Following on from the Sinclair Spectrum, the other machine I got to play with a lot as a kid was the Acorn BBC Micro.  In mid-to-late 80s UK there were several of these in every primary school (unless mine was unusually affluent). Secondary schools had them by the roomful at least until the mid-nineties, when they were finally supplanted by the might of the PC.

For many of my generation this was probably their first experience of computing without the agonising wait for programs to load from tape; the Beeb of course supported a tape interface, but most were installed with a 5 1/4” (very) floppy disk drive. Graphically, the ubiquitous Microvitec Cub monitor was a big step up from the usual re-purposed TV.

There were several versions of the BBC, each in a similarly styled beige box with integral keyboard. The originals, Models A and B, were pretty similar with the A having half as much memory. The Model A could be upgraded later to match the Model B specification, but the B proved more popular anyway. Later came the memory-enhanced Model B+, with subsequent revisions becoming the Master series. The most obvious additions in the Masters were the cartridge slots and numeric keypad, as well as even more RAM.

With fond memories of educational titles like “Granny’s Garden”, and less educational ones like “Pole Position” and “Boffin”, the BBC B seemed like a worthy machine to bring back to life inside an FPGA.

Architecture

The heart of the BBC was the popular 6502 processor, variants of which were also found in machines by Atari, Commodore and Apple, among many others. A summary of the architecture for the model B is as follows, along with the current status of each item in the FPGA design:

  • DONE – CPU: MOS 6502 running at 2 MHz, except when accessing certain peripherals when the clock would be automatically reduced to 1 MHz.
  • DONE – RAM: 32KB DRAM running at 4 MHz, time-sliced with and refreshed by the video hardware (no contention!).
  • DONE – ROM: 16KB MOS ROM, 4x 16KB paged ROM slots. One of the paged ROM slots is taken up by the BASIC interpreter, with another usually filled with the Disk Filing System (DFS). Third party expansions allow more than 4 ROMs to be fitted.
  • DONE – Bitmapped display: Motorola MC6845 CRT Controller + custom Ferranti Video ULA (VIDPROC). The 6845 provides addresses to the DRAM, and additional address-wrap logic means that hardware scrolling can be achieved without the display running beyond the end of the video RAM.
  • MOSTLY – Teletext mode (MODE 7): Mullard SAA5050 character generator.
  • DONE – Sound: Texas Instruments SN76489 accessed via the System VIA.
  • DONE – IO: Two 6522 VIA chips provide a pair of 8-bit GPIO ports each, timers and interrupt inputs. The System VIA provides indirect access to the keyboard and various other hardware over a “slow bus”. One of its timers is used for a 10 ms OS tick, and the four external interrupts are used by the keyboard, vertical sync, ADC and light pen interface. The user VIA drives the printer and user ports, the latter directly.
  • NOT IMPLEMENTED – Serial: 6850 UART and another Ferranti ULA (SERPROC) provide an RS-423 serial port and a “Kansas City” tape interface.
  • NOT IMPLEMENTED – Disk Interface: In the earlier machines an Intel 8271 floppy disk controller provides an interface for a pair of double-sided drives.
  • NOT IMPLEMENTED – Network: Acorn’s own “Econet” is catered for by a Motorola 68B54 Advanced Data Link Controller IC. Like the disk interface this was an optional extra and also requires the addition of the NFS ROM.
  • NOT IMPLEMENTED – ADC: Four multiplexed analogue inputs, useful for joysticks and instrumentation, are provided by a uPD7002 12-bit ADC.
  • Buses: Two expansion buses are exposed on the underside of the machine. The 1 MHz bus was used by peripherals such as the teletext interface, whilst the Tube port is a co-processor bridge. No attempt has been made to make these buses available to the outside world. However, simulating them on the expansion headers should take very little effort.

FPGA Implementation

BBC FPGA on Terasic DE1

BBC FPGA on Terasic DE1

The project was, like the Spectrum, implemented on a Terasic DE1 board with an Altera Cyclone II FPGA. The entire design is written in VHDL, and it fits in 2907 logic elements when compiled on Quartus 9.1. This is about 16% of the capacity of the EP2C20. A small amount of on-chip memory is used for the teletext character generator ROM, with the program ROMs residing in off-chip flash.

At this stage no attempt has been made to add a scan-doubler for the video output, so a PAL TV is required for display. A SCART lead can be made to connect to the VGA port on the DE1; the HSYNC pin generates PAL compatible CSYNC, and the VSYNC pin is driven to +5 V. The latter should be connected to pin 16 of the SCART plug to make the TV go into RGB mode.

Sound is available on the green line-out connector and this can be fed into the SCART lead as well if desired, or to separate speakers.

A PC PS/2 keyboard is required (here is the keymap, click for larger).

Key map for FPGA BBC using a PC keyboard

Key map for FPGA BBC using a PC keyboard

Download the .sof file to run on your own DE1. For normal operation switches 8 and 9 should be in the up position, the rest down. Switch 9 is system reset, switch 8 is the run/stop input to the hardware debugger (more on this later). The remaining switches appear as the keyboard DIP switches, most of which are unused, but the lower three control the startup MODE.

ROMs

I am not providing the ROM images for download here as I am not sure of their legal status and they are not hard to find elsewhere anyway. The following ROMs are required:

  • os12.rom
  • basic2.rom
  • supermmc.rom

The MMC ROM is part of MMBEEB and provides access to disk images on an SD card.

The three ROM images must be concatenated and loaded into the bottom of the DE1′s flash using the tool that came with the board. I joined the ROMs on Linux just by doing:

$ cat os12.rom basic2.rom supermmc.rom >all.rom

 

Note that the ROM order is important, and at the very least the MOS ROM must come first.

UPDATED:  The latest version of this project now includes some addressing changes to allow the BBC ROM images to coexist with those from the Spectrum.  8x 16 KB banks are reserved in the DE1′s Flash address space for use by the BBC, and the relevant ROM images must be loaded first using the tools that came with the DE1 board.

  • 0×20000 – Sideways ROM
  • 0×24000 – Sideways ROM
  • 0×28000 – Sideways ROM (load with SUPERMMC)
  • 0x2C000 – Sideways ROM (load with BASIC)
  • 0×30000 – Not used
  • 0×34000 – Not used
  • 0×38000 – Not used
  • 0x3C000 – MOS

Known Issues

The MODE 7 teletext support does not implement the “hold graphics” feature, which may corrupt some displays. Character rounding is not implemented either, which doesn’t matter so much.

Occasionally the machine will hang, usually at the same point in certain programs. I haven’t spent much time tracking this one down but it appears to be something to do with interrupt handling, so it could be a CPU bug. Manic Miner, for example, starts with an animated graphic like on the Spectrum. On the BBC this uses a vertical sync event handler and so runs in interrupt context. On the FPGA the animation and scrolling ticker run too fast and at irregular pace, and the game can’t be started.

Some of the unimplemented features would be nice to have. In particular the serial hardware for the tape interface, and the floppy disk controller to enable a real drive to be attached. I plan to add these in due course.

Credits

The following blocks are used in the design. Modifications were required in some cases – details on the design page.

Downloads


Leave a comment

29 Comments.

  1. Again, thanks for making the source for this available Mike. I think I’ll be taking a look at this once I’ve finished the spectrum project :)

  2. Hi Mike, had to comment out the test UART to get it to compile as simple_uart.vhd is missing in the source zip. Thinking about adding disk controller support as it aligns with another project that was on the back burner. Nice work.

  3. Thanks for the heads up – the project is managed in a git repository and I never recompiled it after I did the export. I will upload a fixed version when I get chance, although it isn’t a necessary part of the design as you discovered.

  4. The white noise LFSR is incorrect. The tapped bits on the 76489 are 0 and 1. I.e. simply (in Verilog) :

    always @(posedge clk)
    sr[14:0] <= {sr[0] ^ sr[1], sr[14:1]};

    where the reset value is 15'b100000000000000.

    I suppose the error in the logic is the result of opportunistic cut-and-paste, but even the comment mentions that the taps are for an entirely different chip …

  5. Hi. Thanks for the fix. The 76489 block was just lifted from FPGA Arcade and it does need some work (it fails timing on Altera). I was aiming to rewrite it at some point and I’ll make sure the tap positions get updated.

  6. Mike,
    Nice work. Could you drop me a mail, I would like to merge your bug fixes pack into the FPGAArcade code if you don’t mind. I am also bringing up your design on the new Replay board which is fun.

    Best,
    Mike

  7. Hi Mike, I’m not sure if there is a field bug in the 6845. My ‘scope has field selection and won’t lock on, and one of my LCDs is also having some kind of interlace issue. I’ll take it in to the office and put it onto the DSO so I can take a closer look. FYI: I put a PAL S-video encoder into my build. With a passive combiner, I get colour on a regular TV with composite in :)

  8. Hi Jason. The CRTC model doesn’t implement v_total_adjust, so the frame length is going to be slightly shorter than it should be. Although the CRT TV I was testing on had absolutely no problem with this, I can imagine it could upset a flat screen. There are also no serration pulses – just a half line VSYNC delay.

    Nice work on the PAL encoder. Is it open source?

  9. Hi Mike. I’m guessing it’s one of these two. Maybe I’ll try to add those bits in. Yes, my composite stuff is based on the open source Joerg Wolfram fbas_encoder and scoops the RGBHV directly from the Video ULA and needs a 32MHz clock. I was going to make a patch which was run-time switchable but there are no dev board switches free so mine drops your existing output scheme. It also occured to me that the video ULA could be tweaked to give proper 16 colours in mode 2 as we’re not limited to TTL RGB monitor.

  10. Hi Mike,
    First can I say what a remarkable achievment. I compiled the code tonight. loaded the roms to flash and it works!!

    I have a problem thou. On the monitor I have, the video blanks at an interval of around 1s. Im guessing at this early stage it’s a timming issue.
    I can run games such as Arcadians and they don’t crash when the display wobbles. I tried on an older crt monitor and it won’t sync at all. Any ideas where I should investigate?

    I’ve also run your spectrum and It’s ace as well.
    Your clearly a very lalented person. :smile: :smile:

  11. Hi Graeme. You’re not the only one having timing issues with the video, which is strange because it was rock-solid on both the CRT and LCD that I tested it on (the video is shot from an LCD), although as was often the case with 80s computers, the timing isn’t bang-on BT.601. You aren’t trying to run it into a VGA monitor are you? The Spectrum design has a scan doubler, but the BBC doesn’t so it needs a TV.

  12. That explains that then. Yes that’s what I’ve done. I just hooked it to the PC input on my telly. I’ll wire it to the scart input and let you know how I get on. Thanks.

  13. Mike,

    I managed to get this up and running on the Digilent Atlys. Also having issues with the video. Seems the LCD monitor is not very happy when in mode 3,6 and 7 but is fine in other modes.

    In order to get it working in the other modes i had to use a 640×512@50Hhz signal using the following modeline..

    Modeline “640×512″ 32 640 784 912 1024 512 544 548 624 -hsync +vsync

    I then used this pixel clock as my base clock.

    Hope this is of some help.

  14. Mike, quick update. I’ve investigated and found that in modes 3,6 and 7 the 6845 model is not inserting the blank scanlines. This means that the VSYNC pulse is getting sent around PAL scanline 599 on those modes instead of scanline 623 on the other modes. I’ve not seen anything in the code yet that explains it but that would be why many people are reporting problems with syncing. Also it means that the machine doesnt get enough CPU time per frame for some of the more exotic games.

    I spotted this because i’m having to convolve my signal onto a DVI carrier as the Atlys doesnt have VGA. Just HDMI.

  15. Wow – just discovered this and your speccy project! Looks like you’ve done some impressive work – more than my half-completed efforts! Nice!

    Also had no idea there was a PAL/NTSC core… my colleague has been working on one and is almost there… he’ll be interested in that no doubt!

  16. Mike, i’ve managed to get this working lovely on the Digilent Atlys. Here are a couple of videos of it working.

    http://www.youtube.com/watch?v=wFtVTaFZ5Lo

    http://www.youtube.com/watch?v=1cYkE3jPCRg

  17. Excellent! Is that running on a PC monitor, and if so did you implement a scan doubler, or modify the CRTC?

  18. Minor modification to the CRTC.. I needed to stop the half line phase shift on alternate frames.

    I basically write a byte to a fifo on every vid_clken, when the fifo has 4 bytes i write that to DDR ram (via Xilinx MIG). The reading bit is trickier but it does scandouble although i havent done the deinterlace properly yet. Thats only *really* important in mode 7.

    Its outputing via HDMI on the Atlys but it could easily be modified to output to VGA on something else.

    I’m now working on getting a Tube interface working. I’ll keep you updated.

  19. After a fair bit of messing about i have a working tube model that is compatible with your FPGA setup. Using it will require an FPGA capable of running a second 65C02 and will need 2K rom + 64K RAM. the major bonus is that we get more ram space free for basic programs.

    Send me an email Mike and i’ll send you over the code i have. current version uses a Xilinx FIFO but im sure we can invent something for the Alteras.

  20. Latest tube model emailed to you mike.

    Everything seems to work ok except 2nd processor elite. Need to investigate why that is crashing.

  21. Hi Mike,

    Thank you for publishing this great project! I have got your BBC design working on my DE1 board -except the display. I can tell the BBC is booting and running ok by typing SOUND commands, ‘ blind’ However, I don’t quite understand how you have connected your SCART cable. Could you describe the pin connections VGASCART a bit more please ? Did you use a commercial cable for that, or did you make your own ? Thanks!

  22. Hi.
    Sorry for the delay in replying. The cable is home-made. Wiring off the top of my head (so if it doesn’t work, let me know):

      VGA->SCART

    1 -> 15 (red)
    2 -> 11 (green)
    3 -> 7 (blue)
    6 -> 13 (red ground)
    7 -> 9 (green ground)
    8 -> 5 (blue ground)
    10 -> 17 (sync ground)
    13 -> 20 (csync)
    14 -> 16 (select RGB input)

      AUDIO->SCART

    tip(left) -> 6
    ring(right) -> 2
    GND -> 4

    The grounds don’t have to be separate. I will try to find time to check this tomorrow and draw a diagram.

    Mike

  23. Mike,

    Can you try the following for me on your FPGA model.

    *FX 9,0

    This seems to cause a hard interrupt lock up for me about a 10th of a second after i do it. This is whats breaking elite tube for me.

  24. BBC beeps and seems to respond to keyboard, but I’m getting no display on two monitors and two TVs via various cables :sad: . Any way you can build in a switch for interlaced/non-interlaced video ? Otherwise, getting a display from this thing seems to be a form of masochism.

  25. I think there’s a VDU command to do that, which shouldn’t be too hard to type blind. You mentioned monitors – you aren’t trying to feed it into a VGA input are you? Unlike the Speccy, the Beeb design doesn’t include a scan doubler so it will only drive a PAL TV/monitor for now. You need to make a VGA to SCART lead like the one for Minimig.

  26. The Proton wasn’t the US version of the BBC Micro; it was a prototype that turned into the BBC Micro. (Acorn’s previous machine was called the Atom. A later one was called the Electron. Spot the theme.)

  27. Thanks for the heads-up. For some reason I was under the impression that it actually got released under that name outside the UK, but according to wiki it was simply known as the “British Broadcasting Corporation Microcomputer” to avoid a possible trademark infringement on the acronym.

Leave a Reply


[ Ctrl + Enter ]

Trackbacks and Pingbacks: