Wednesday, November 24, 2021

Retrocomputing Basic Implementations

Here is a summary of a number of Basic implementations that I have come across and worked with as part of my retrocomputing hobby. Many of these were ported by me or others to different platforms from the ones they were originally written for (for example, single board computers based on the 6502, 6809, Z80, and 68000 microprocessors). These are all found on my github  account.

Name Developer Platform Code size Comments
Enhanced Basic (68000) Lee Davison 68000 14K Full-featured Basic for 68K platform
Tiny Basic for the 68000 Gordon Brandly 68000 4K Derived from and similar to Palo Alto Tiny Basic.
Enhanced Basic (6502) Lee Davison 6502 11K Full-featured Basic for 6502 platform.
Microsoft Basic for 6502 Microsoft Apple 2, Commodore, KIM-1, OSI, and others 8K Basic used on several early 6502-based microcomputers.
Tiny Basic for 6502 Tom Pitman 6502 3K Originally published in Dr. Dobbs Journal.
Apple 1 Basic Steve Wozniak 6502 (Apple 1) 4K Basic for the Apple 1, later expanded into Apple 2 Integer Basic.
BBC Basic 2 for Acorn Atom/BBC Computer Roger Wilson (Acorn Computer) 6502-based Acorn Atom and BBC Computers 16K Basic for the Acorn Atom and BBC Computers.
Tiny Basic for 6800 Tom Pitman 6800 2K My version runs on the Heathkit ETA-3400.
Tiny Basic for 6809 Tom Pitman 6809 2K 6809 port of 6800 version.
TSC Micro BASIC PLUS Technical Systems Consultants 6809 4K Similar to Tiny Basic.
Sinclair ZX81 Basic John Grant and Steve Vickers, Nine Tiles Networks and Sinclair Research Sinclair ZX80/ZX81, Timex 1000 8K Basic for the Sinclair ZX81 computer.

A List of Cross-Assemblers for Retrocomputing

 In my retrocomputing projects with various processors I have used a number of cross-assemblers to build code. I've had to use several in order to support different processors as well as for compatibility with different software packages. For the most part they are similar, but have their own unique features and quirks.

I put this table together, mostly for my own reference, that others may also find useful. It is by no means a complete list -- just those that I have used.

Name Author Source Supported Processors Key Features Comments
as9 Motorola, with changes by Albert van der Horst and others 6809 macros 100% compatible with Motorola assembler
asl Alfred Arnold and others many (over 50) Macros I have used with several processors
asm6809 Ciaran Anscomb 6809, 6309 macros Good choice if 6309 support needed.
cc65 John R. Dunning, Ullrich von Bassewitz, and others 6502, 65C02 C compiler, assembler, linker, librarian Supports several 8-bit computer platforms.
crasm Leon Bottou 6800, 6801, 6803, 6502, 65C02, Z80 macros Included in most Linux distributions.
gcc Richard Stallman and others Many Compilers and assemblers I used for 68000. Included in most Linux distributions.
lwasm William Astle and others 6809, 6309 Cross-assembler and linker. macros
vasmm68k_mot Volker Barthelmann Many Cross-assembler I used for 68000.
z80asm Bas Wijnen Z80 Z80 cross-assembler Included in most Linux distributions.

Thursday, February 20, 2020

Hugo Winner Book Review: The Snow Queen by Joan D. Vinge

I found this novel rough going. I wanted to give up on it a few times, and I did set it aside for several weeks. But about half way through my interest picked up.

There is nothing wrong with the story or writing. For some reason the plot and characters did not particularly appeal to me and it is leans more towards "soft" science fiction where I am generally a fan of the "hard" genre.

It is very imaginative, and has some very poetic writing.

Tuesday, November 19, 2019

A 68000 Disassembler

I have found that a good way to really understand a microprocessor's instruction set is to write a disassembler for it. I have done this for a number of processors including the 6502, 6800, 6809, and Z80. My udis disassembler was implemented on Python and supports a number of processors.

Having recently worked on my 68000 single-board computer, I decided to write a disassembler for the Motorola 68000. This is more challenging than for 8-bit processors due to it's complex instruction set and many addressing modes. I decided to again use Python as it is fast to develop, readable, and cross-platform.

I wanted the design to be at least partially table based. I started with the table on the Motorola MC68000 Programmers Reference Card, but it did not adapt will to a software-based table. I found a very nice and succinct table  written by someone in France under the name of GoldenCrystal that was a better fit. It organized all of the 68000 instructions and decoding of fields in a logical manner. I made a spreadsheet based on the table data.

The 68000 uses 16-bit opcodes, but they are not unique. Various bits in the opcode control the addressing modes and operands, so I needed to use an approach where each instruction has a bit pattern and a mask indicating which bits to examine when looking for a match to a specific opcode. For example, a NOP is $4E71 and all bits are valid but a MOVE instruction has thw two most significant bits as zeroes but the rest vary with the address mode.

I exported the spreadsheet into CSV format, which can easily be read into a data structure from Python. I then use this data for determining what instruction is read. Then I handle the encoding of the instruction and any extension words or operands. Many instructions follow similar encoding and can use the same logic, while others are unique.

It was somewhat tedious and time consuming to work my way through all of the possible instructions. As I proceeded, I wrote a test program with the instructions I was implementing and examples of each addressing mode. An additional good "stress test" of the code is to use random data (such as /dev/urandom on Linux) as input and make sure that it does not crash or produce errors.

After few weeks of occasional evenings (interrupted by a trip to Europe) I had finished support for all instructions. The most complex was the MOVE instruction as it supports almost every addressing mode for both source and destination operands. The final program is just over 1000 lines of Python code including comments and blank lines.

Here is some sample output:

00000000  4E 71                          NOP
00000004  A2 34                          UNIMPLEMENTED
00000006  4A FC                          ILLEGAL
00000008  4E 70                          RESET
00000012  4E 40                          TRAP      #$00
0000001A  00 7C AA 55                    ORI       #$AA55,SR
0000002A  02 7C AA 55                    ANDI      #$AA55,SR
00000032  60 5E                          BRA       $00000092
000000BA  48 C2                          EXT.l     D2
000000BE  4E 69                          MOVE      USP,A1
000000DE  57 CF 00 22                    DBEQ      D7,$00000102
00000112  72 01                          MOVEQ     #$01,D1
00000146  EF 82                          ASL.l     #7,D2
000006E4  08 78 00 08 12 34              BCHG      #$08,$1234
00000C9E  4C FB 55 AA 90 12              MOVEM.l   $12(PC,A1),D1/D3/D5/D7/A0/A2/A4/A6
00000CF4  2C 6D 12 34                    MOVEA.l   $1234(A5),A6
00000D3A  18 3A 12 34                    MOVE.b    $1234(PC),D4
00000F24  55 91                          SUBQ.l    #2,(A1)
00001334  DF B8 12 34                    ADD.l     D7,$1234

With the -n or --nolist option, it only disassembles the instructions. This could be used to feed the output back into an assembler, if you were reverse engineering some code for example. Here is some sample output in this mode:

 TRAP      #$00
 ORI       #$AA55,SR
 ANDI      #$AA55,SR
 BRA       $00000092
 EXT.l     D2
 MOVE      USP,A1
 DBEQ      D7,$00000102
 MOVEQ     #$01,D1
 ASL.l     #7,D2
 BCHG      #$08,$1234
 MOVEM.l   $12(PC,A1),D1/D3/D5/D7/A0/A2/A4/A6
 MOVEA.l   $1234(A5),A6
 MOVE.b    $1234(PC),D4
 SUBQ.l    #2,(A1)
 ADD.l     D7,$1234

The source code and test program can be found here.

This process gave me an appreciation for the effort that the Motorola engineers must have gone through to implement the native 68000 dissasembler in the TUTOR firmware which was written in assembly language.

I can also appreciate that significant more work would be needed to extend this to support the 68020 or later processors which have more instructions and addressing modes.

While it was not meant to be a production program, it was fun to write and I now have a much better understanding of the 68000 instruction set and its complexity, quirks and limitations.

Sunday, September 29, 2019

Hugo Winner Book Review: Harry Potter and the Goblet of Fire by J. K. Rowling

Not many pure fantasy novels have won the Hugo award for best novel. One notable winner was The Sword in the Stone in 1939. This book, the fourth in the Harry Potter Series, won the award in 2001. This was the only one of the seven Harry Potter books to win a Hugo.

I was vaguely familiar with the Harry Potter franchise but had never read any of the novels or seen the films. I would say that the book lived up to my expectations and I can see why they were so popular with young people. Highly imaginative, well plotted, and with well developed characters, the books never talk down to the reader. At 636 pages in the hardcover edition, this book was over twice as long as the earlier novels (but exceeded by the subsequent book).

Given the popularity of the series, it is fitting that it won at least one Hugo award.

Wednesday, September 4, 2019

Hugo Winner Book Review: The Dispossessed by Ursula K. Le Guin

Winner of the 1975 Hugo for best novel, this is a fascinating story about an unlikely hero and two planets with widely differing political systems. It fits into Le Guin's Hainish Cycle, like "The Left Hand of Darkness" a Hugo winner I previously reviewed.

Highly original and imaginative, It describes an anarchist utopian society that almost had me convinced that it could work.

Recommended reading, it is a standalone novel that doesn't require having ready any of the other novels in the series.

Saturday, August 3, 2019

Hugo Winner Book Review: Where Late the Sweet Birds Sang by Kate Wilhelm

This was the 1977 Hugo award winner for best novel.

It is a near-future apocalyptic tale with some aspects that are disturbingly familiar today (e.g. pollution, climate change, new diseases, genetic engineering).

The writing style is quite different from most of the classic SF authors, with much focus on characters and their emotions. I found it somewhat reminiscent of John Wyndham's work.

An enjoyable novel, unpredictable and disturbing at times, I think it was well deserving of the award