Close

Porting BBC BASIC

A project log for W65C816SXB investigation

Evaluating the W65C816SXB development board

keithKeith 02/21/2021 at 02:500 Comments

At first sight, this doesn't look too hard.  I have already hacked BBC BASIC for the Acorn second processor 6502, to run on an experimental 65C02 board. The only I/O is through the USB channel, and that is trivial. 

There is a thread on stardot.org.uk about BBC BASIC on the 65816. Seems it has been done for the Acorn Communicator but not very well, perhaps to meet deadlines.

https://stardot.org.uk/forums/viewtopic.php?p=298640#p298640

I don't have time to modify the BASIC to take advantage of the 65816 instruction set and expand the built-in assembler, but it should run pretty fast.

http://mdfs.net/Software/BBCBasic/BBC/Basic4.zip is for the 65C02, which uses a subset of the 65C816 instruction set.

2021-02-24

Discovered John Kortink has ported a 65C816 BBC BASIC onto his soft 65C02 second processor for the BBC micro. This is closed source, though if you had one running you could peek all the code bytes and disassemble them to analyse the firmware modifications.

2021-02-25 

My DE0-NANO FPGA and W65C816SX development boards arrived. I could do the porting work in the FPGA, but I don't want to wait for the CPU core to be compiled every time I make a tiny software mod. So I have installed all the new Western Digital development tools.

2021-03-02

After emailing some big names of the 6502 world, I learned from the very long thread about it: https://stardot.org.uk/forums/viewtopic.php?f=2&t=21159 it seems that the main guy working on 65816 BASIC is Dominic Beesley who has a disassembly here https://github.com/dominicbeesley/CommunicatorBasic100 which has a fair few source files.

Looks like this is not a trivial job, if better programmers than me are having to work hard.

The assembler now handles all 65816 instructions, which is good. The software is purported to be ... inelegant for want of a better word. It has to deal with short and long addressing, the overhead of using a separate 'module' for arithmetic, and other stuff.

At this point I wonder if it is what I like about the 6502 - a well-known instruction set and architecture that is easy to use. Should I just port a simple 6502 BBC BASIC and then leave the potential of the 65816 modes to programmers with the time to harness it? Off the top of my head, I can't think of anything I would want a massive memory map. Maybe a memory-based disk system? Lots of graphics memory? I do big jobs on my PC and the development board does not have graphics. My spare time is scarce and my hobby projects are therefore fairly small.

The Communicator BASIC includes code for running all the BBC micro I/O such as keyboard, disks, screen etc. A tube version would be simpler and smaller, and indeed there is a thread about this for an FPGA version https://stardot.org.uk/forums/viewtopic.php?f=3&t=9975. Looks like a better starting point for me.

John Kortink has firmware for his 6502 second processor that uses a real ULA, 65C02/65C816 and a CPLD. It is obtainable from here: http://www.zeridajh.org/hardware/reco6502/updates.htm

2021-03-03

After reading the manual and some disassembly work, I have a better idea of what it does and how. The BASIC is modified have extra commands to configure the system through calls to a modified MOS.

The configuration is loaded in a shift-register fashion. It is write-only, so I might be able to run his firmware and have the hardware simply ignore the shifted bits. If I can't use the configuration commands, then I might as well start from the unmodified 2nd processor BASIC and MOS.

The master clock is 44.2638 MHz, which can be divided to nice baud-rate generator compatible frequencies.

I have only disassembled the 65C02 version, using the da65 tool from the cc65 suite. 
Alas it does not disassemble 65C816 code. Or compile C to 65C816 code either. I am inclined to implement just a plain 65C02 BASIC and let other people implement a 65C816 version if they have the skills and time to do so.

2021-03-07

Another reason to use plain 6502 BASIC is that the 65C816 has extra hardware vectors that clash with the Acorn MOS entry points.

I conclude that my only reason for using a 65C816 chip is to run legacy code for 65C816 machines. As I don't have any, I'm going to shelve this sub-project.

2022-02-14

As a postscript, John Kortink got round the 65816 incompatibility by modifying the MOS and patching HiBASIC. 

http://guides.zeridajh.org/ReCo6502/Documentation/Software/software.html

http://www.zeridajh.org/hardware/reco6502/downloads/reco6502_122.zip

It is more than just changing a few bytes. I'd need to disassemble the 02 and 816 versions to see how they differ, but I don't have the time right now. 

Discussions