Unix-style binutils for Motorola MC6801
Intro
My experience programming the Tandy MC-10 started around 2014, when I did a quick adaptation of a text-based "animation" adapted from the VZ-200. Then it continued in January of 2016, when I ported my original CoCo game "Xmas Rush" to the MC-10. In those cases, I used simple "absolute" assemblers. They were simple, but effective.
Use of something called TASM seems to be de rigueur for MC10 assembly language program development, but I don't see any features peculiar to TASM that would make it appeal to me any more than the simple assemblers that I had already been using.
Most of my software development experience has been in a Unix, or Unix-like (e.g. Linux), environment, so those environments frame my perspective on how software should be developed. In an earlier project, I experimented with the Bruce Evans C compiler, configured to produce code for the Motorola 6809 CPU. That project included a simple Unix-style toolchain for what are often called "binutils" (i.e. assembler, linker, archiver). These tools allow for assembling relocatable object files which can then be collected into libraries for future use, and linked together into final executables. This capability is not strictly necessary for many projects, but it provides some nice flexibility for building bigger or more complex projects.
The 6803 CPU in the MC-10 is essentially a version of the 6801. The instruction sets of the 6801 and 6809 differ substantially. But they have enough similarities that converting the 6809 binutils from BCC to equivalent tools for the 6801 was practical. So I did that, in pursuit of a more capable toolchain that I can use to target the MC-10.
HELLO, WORLD!
To demonstrate, let's show a simple MC-10 program:
LOC 0
LOC is a directive that can be used for grouping code or data in the final linked executable. This can be used to segregate text segments from data segments, etc.
ENTRY __start
ENTRY is used to identify the code symbol where the program is intended to start execution. This is required when linking the final executable.
SCREEN equ $4000
clrscn ldx #SCREEN
ldaa #$40+'
ldab #$40+'
clrsc.1 std ,x
inx
inx
cpx #(SCREEN+512)
blt clrsc.1
rts
hello fcb 'H,'E,'L,'L,'O,$40+' ,'W,'O,'R,'L,'D,$40+'!,$0
prstring
ldx #SCREEN
pshx
ldx #hello
pshx
tsx
prstlop ldx ,x
ldaa ,x
beq prstxit
psha
pshx
pula
pulb
addd #$01
tsx
std 1,x
ldx 3,x
pula
staa ,x
pshx
pula
pulb
addd #$01
tsx
std 2,x
bra prstlop
prstxit ins
ins
ins
ins
rts
__start
jsr clrscn
jsr prstring
rts
The rest of the code should seem straight forward to 6801 assembly language programmers. Two subroutines are defined (clrscn, and prstring). Execution begins at __start, which calls clrscn and prtstring in order. The clrscn subroutine fills screen memory with empty space characters, and prstring writes "HELLO, WORLD!" into the top left corner of the screen. (NOTE: 6809 assembly languages programmers will notice the increased complexity of the code for the 6801, which has only one index register and lacks any LEA* instructions.)
The code above is saved to a file called main.s, then assembled with the as01 tool:
as01 -o main.o main.s
The resulting object file (main.o) is then passed to the linker to produce an a.out file:
ld01 -T0x434c -o main.o main.aout
Finally, a custom tool is used to convert the a.out file into a WAV file that can be fed to CLOADM:
objcopy01 -T0x434c -O wav main.aout main.wav
The "-T" option is the address for the "text"section, which is also used as the load address for the final binary. I forget exactly where I determined the number to use for that, but 0x434c works well.
In any case, use MAME or another emulator or a real MC-10 to consume that WAV file (via CLOADM), and EXEC will write "HELLO, WORLD!" to the screen. QED
Ta-da!
So, there it is -- a "new" Unix-style toolchain for programming the 6801, including the 6803 in the MC-10. AIUI, the assembled code whould run on a 68HC11 as well, but taking advantage of that is an exercise for the reader.
Is this useful? That depends on your needs, and your definition of useful. But if you can see the use for doing modular code builds targeting the MC-10 or another machine compatible with the 6801, then please gives these tools a try, and tell me about your results below, or at Github:
https://github.com/retrotinker/mc6801-tools
So, this is a good first step. But is there a larger point? To find out, you'll just have to stay tuned...
Gonna keep us all in suspense eh?!
ReplyDeleteFor now, I suppose I am. FWIW, I've been sitting on some of this tool stuff for a long time, so it is good to start exposing it to the world, in order to justify doing more work in the future! :-)
Delete