Friday, July 12, 2024

ALPP 01-05 -- Getting a Simulator for the 68000 and Running Code on It (Hatari, vasm)

Getting a Simulator for the 68000
and Running Code on It
(Hatari, vasm)

(Title Page/Index)

 

Again, I'm assuming you've gone through the previous chapters, bringing EXORsim up for the 6800 and 6809 and running code on it, and also bringing up my fork of EXORsim for the 6801, with code running on it as well. 

I'll be implicitly referring here and there back to things we did in those chapters, so if you get lost, at least go back and make sure you've read and understood those and preferably got those emulators working before leaving questions here.

Now, if someone had written an EXORmacs simulator in the same vein as Joe Allen's EXORsim, we'd be in business. I'd use that for the 68000 code here. Or even an EXORsim simulator for the MEX68KDM 68K developer module card for the EXORciser that Motorola mentioned in some of their materials.

(I seem to remember a simulator for a Versabus or VME based computer in the SIMH project, but I'm not seeing that now. I probably should take a look at the SAGE simulator in openSIMH, but, again, that's a lot of reading documentation and building more code, and I'm not sure it would be any easier to use than Hatari.)

There's also Easy68k or something, but it only runs on MSWindows, and I don't do Wine, and I don't recommend things I don't do.

So, options lacking, doing this (myself) right for the 68000 would possibly involve something like writing up an instance of Musashi that would run in some sort of terminal arrangement, perhaps as an alternate history main processor board for the EXORciser if I can't find documentation for the MEX68KDM. 

Or do something to emulate the single board MEX68KECB. 

And I'm not sure how much of the disassembler, general debugger, interactive assembler, etc. I'd have to add, so maybe I might as well plan on writing the emulator proper, as well, instead of planning on using Musashi.

And all of that would be more postponing this tutorial. 

So, ...

Hatari

What's the difference between an emulator and a simulator?

Some people say that emulators are done in hardware and simulators in software. But the Hatari project calls their Atari ST simulator an emulator.

Hatari is in the Debian package repositories, and therefore in Ubuntu and many other Linux OS package repositories, as well. And there are RPMs for Cent OS and such. You can download it from the project site and work through getting all the prerequisite dependencies installed before building it yourself if you want. But that's another steep learning curve if you haven't done it before, and a fair amount of work even if you have.

Although that's exactly what I have done in my current workstation. I installed the dependencies syetem-globally from packages, then built Hatari and installed it locally in my daily-driving user account. It keeps the side-effects local.

So having it in packages is a really useful thing if you aren't building it yourself. Your package manager can work out the dependencies, and install them all together at once with Hatari, in just a few minutes or tens of minutes, depending on your internet connection.

Fortunately for you who are running MSWindows, there are pre-compiled .exe executables for you in the downloads area of the website, in .zip archives.

Go ahead and spend a few minutes looking around the Hatari site, especially the docs. Things to look for, 

  • EmuTOS
  • Keyboard mappings 
  • Disk images
  • Emulating disks in hosted directories
  • Getting Hisoft Devpac or similar software 
  • The built-in debugger

Check to see if your package manager includes Hatari. (Cygwin for MSWindows does not, at present. Several package managers for Mac do. Most Linux OSses do. NetBSD and FreeBSD do.) 

If it doesn't, spend some time checking the build instructions. Write down the list of dependencies and start collecting and either installing them from packages or building them. Etc. LoL. If you are running an OS for which you need to build it, I'm pretty sure you know how to do this without me explaining it. 

If, for whatever reason, you do build it yourself, you can specify your local executable directory as the install target. In the example structure I've been talking about, that might be 

~/prg

and in that case you would specify 

/home/me/prg 

as the target.

Before we proceed, there is a not-so-minor issue with Hatari, in that we won't be able to do things like copying and pasting object or assembler source code into the running emulator window, the way we can with EXORsim. We'll have to edit source code files, save them in the directories Hatari is seeing as emulated disk, and assemble them with vasm or something similar.

Speaking of directories, familiarize yourself with the directory structure your package system sets up for Hatari. In particular, as I mentioned, you want to know where to put EmuTOS so it can find it, or, more likely, you want to check where your package has installed EmuTOS. You also want to know where it will look for disk images and directories to emulate disks in. 

If you have it installed properly, you can find a lot of answers by running

$ hatari --help

Hatari v2.4.0-devel (Dec 18 2021) - the Atari ST, STE, TT and Falcon emulator.

Hatari is free software licensed under the GNU General Public License.

Usage:
 hatari [options] [directory|disk image|Atari program]

General options:
  --help or -h          Print this help text and exit
...

EmuTOS

EmuTOS is essentially a free-and-open-source replacement for TOS (in the short version of the story) -- the BIOS and OS kernel provided originally by Atari.

You may find people telling you you need to download EmuTOS separately from Hatari, but that really isn't the case for our uses. The license for EmuTOS allows it to be packaged with Hatari and other emulators, so the tos.img that is in the package that your package manager makes for you, or is in the .zip or other archive you downloaded, should be EmuTOS. 

That also means you don't have to extract the ROM from a real Atari ST or such to do what we want to do.

Setup

In fact, other than deciding where to set up the shared directory structure, it should just mostly work. Well, that and the keyboard mappings. You'll probably want to look carefully at keyboard mappings so you can get an idea where to find keys you need.

Once it's installed (or built), running hatari from the command line without options should bring up an Atari desktop screen in emulation, like this:

 

from which you can hit F12 to get a graphical dialog to set things up. 

You may prefer to go that route, rather than sort through all the command-line options. Heh. You probably do want to use it. So I'll walk you through the relevant setup.

By the way, F11 toggles full-screen mode off and on. This is useful, particularly when switching back and forth between Hatari and your host OS.

You will usually want to use it with full screen off, because of all the things you'll be doing at the same time on the host machine. But, at least on my installation, with full-screen off, the mouse sometimes gets out of sync, and I have to toggle back to full-screen to use the mouse. However, I can pretty much always use the mouse in the setup dialog. Toggling is not usually a problem.

Things you want to set up or check now include 

  • System -- Keep it ST mode to keep things simple.
    Blitter in ST mode, if it isn't already set. 
  • CPU -- 8 MHz can be slow, but more than 16 MHz can get weird.
    So, 16 MHz.
  • Memory -- You want at least 512K, and more than that can get weird for what we are doing.
    So, 512K.
  • Floppy disks and Hard disks -- You don't really need disk images, but, maybe you do ...

We've got to talk about default directories for a moment. 

When you install from your packages, it will likely set up several things it needs to keep track of under 

/usr/local/share/hatari/

or some such directory. This is in the file system area controlled by the operating system, and is outside your daily driving user's file system area. Handling file permissions to allow writing here can get strange. You should not want to do that. No, you really should not want to do that. So you'll want to make some adjustments. 

Among the things it will by default save here, and look for here, are

  • the tos.img file it is using
  • the C: directory
  • keyboard mapping files 
  • disk image files

I'm sure you can understand that we need these, and we need to know where they are.

The tos.img file, we can leave alone, once we've noticed where it is. We won't need to touch it that much. (If we do need to, if we have a different tos.img file to use, the configuration menu lets select a different image in a different location without messing with /usr/local/share/.)

The C: directory mapping, we will use extensively. We need to write to that directory a lot. So we need to point it somewhere within our daily-driver working directories, like (using unix/Linux syntax)

~/asmwork/share/hatari/C/

which if you are working as user "me" on a LInux OS, might actually look like 

/home/me/asmwork/share/hatari/C/

I say might because it depends on how you set things up. I didn't set mine up exactly this way, but I'll use this as a basis to explain things. You should think a little about how you would want it, and set it up in a way that makes sense to you. 

Your operating system gives you some sort of a home directory for the user you are logged in as, and the directory you decide to do most of your assembly language work in should reside under that. That directory would be "asmwork" in the paradigm above, or it could be "mywork/asm", or whatever you choose to call it. You'll probably want a directory under that which multiple programs you'll be working with can share, there under your assembly language working directory, and you might call it "share" -- thus, "asmwork/share" if you decide to do it that way.

On MSWindows, you'll be wanting to work within the cygwin shell, so you'll use forward slashes instead of MS-DOS/CPM backslashes (or instead of yen mark -- ¥ -- in older Japanese language MSWindows OSses).  But looking at them or working on them in MSWindows command line shell, you will use the MSWindows slash -- "<something>\asmwork\share\hatari\C\" (or, in an older Japanese MSWindows OS, the yen mark --  "<something>¥asmwork¥share¥hatari¥C¥"). You'll need to get used to some differences between the Cygwin shell and the MSWindows shell.

Not incidentally, I downloaded the 80 megabyte hard disk blank image that you can find on the Hatari download page and saved it in my local files, and saved a copy of it to be used as the hatari D: drive, for example, directly under 

~/asmwork/share/hatari/ 

in the above directory conventions. I recommend you get that hard disk image and save it somewhere similar, also. You can then select it for your D: drive from the configuration dialog.

So, continuing with the configuration dialog:

  • Hard disks -- write down the default for C: before you use eject and browse to set it appropriately in your own directory structure. You might want to remember where it was.
    Also, set up a D: drive with the blank image, as an IDE drive.
    When you're done with this, save the configuration once, just to be sure.
  • Floppy disks -- you can probably save yourself some error messages if you use the configuration dialog to create a couple of blank floppy images and set them up to be drives A: and B:. The setup dialog has buttons that do this for you.
  • Atari Screen -- look at what's here, in case you want to change something. But leave it at resolutions and colors the early ST models can handle, so things don't get weird.
  • Hatari Screen -- You probably want the status bar and GPU scaling.
  • Keyboard -- Remember that you can set the keyboard mapping here. In fact, go ahead and save a default configuration file in your local directories so you can look at it and play with it.
  • Load/Save config -- Note where it saves your configuration files in a hidden directory in your local directory structure, which is not under ~/asmwork/share/hatari/ in the above conventions. Quite likely, it will be under "~/.config/hatari/",

So far, even if it isn't anything that seems all that interesting, you just need to see where things are, and, especially, move C: and save and set some keyboard mappings. 

Go ahead and quit after saving anything you changed and want to save. It will give you one last chance to save things.

Check again in your host OS that the C: directory is where you told it to be, for example, under the above conventions,

~/asmwork/share/hatari/C/

Start Hatari again and when the desktop screen comes up, run EmuCON by selecting it from the File menu.

Or you can just hit Ctrl-Z to run EmuCON. Either way works.

It should put away the GUI screen and drop you into a command-line DOS (ergo, CP/M) shell. 

Type some commands like HELP and DIR and such (You don't have to type in caps.), and see whether the keyboard needs configuration. If it does, look at the documentation and figure out what needs to be where.

The following keyboard configuration file makes hyphen, brackets, and the caret available on my Japanese notebook keyboard, although not in optimal positions.

-,12
[,26
],27
^,13

Some other key codes, I have to use the Fn key and the keypad to access. 

You'll have to figure out what your keyboard needs, though, and it requires editing the keyboard configuration file as a text file in your host system, so don't hesitate to use pencil and paper if necessary to take notes. And be willing to make compromises, because they are trying to emulate the ST keyboard, not make the modern keyboard available in its entirety.

When you have the keyboard working well enough, use EmuCON to make a working directory under the C: directory. You could do this in the host OS, as well, but we want to make sure the emulator is working and able to talk to the host OS on things like this. In the EmuCON console,do a DIR and see what the emulator thinks is there.

C:\>DIR
  file not found

make your working directory, maybe call it "PRIMER", and then change to it for fun:

C:\>MD PRIMER
C:\>DIR
PRIMER
C:\>CD PRIMER
C:\primer>

You can exit the command line shell with the EXIT command.

Devpac

I have been using Hisoft's Devpac for another project, and I was intending to discuss that, but when I went back to check where I got it from and such, I decided there is too much ambiguity and lack of provenance to recommend it. I found some evidence at the time that the folks at Hisoft had given explicit permission, but I can't find that evidence now.

If you want to use it, you'll need to figure out the provenance and whether there is permission to use it for yourself. I can't help you with that.

If you do decide to use Devpac, install it on the D: drive. It'll be easier to use that way. 

More generally, you'll probably want to install any tools for working in the emulated Atari ST system in the emulated D: drive.

Now, as I think I mentioned, Hatari has a built-in debugger. So we have the debugger requirement at least partially covered.

But it doesn't do interactive assembly, and it doesn't include a separate assembler, so you'll need an assembler. I haven't written one of those for the 68000. But a guy named Volker Barthelmann and a guy name Frank Wille have worked together and made something that can help us, called vasm, and made it available for non-commercial use -- which I think covers what we are doing here.

vasm

I guess vasm is named for "Volker's Assembler". It's a really complicated beast, and does way more than we need, but we can use it for what we need. As I just said, they have made it available to be used for non-commercial purposes when used to target Atari ST. That's not a license that allows it to be included in your libre OSes's main/libre packages, but it should be sufficent for our purposes here. And it's not hard to build. And not really hard to run. either, once you've got it built. 

That is, I'll help you figure out how.

First, nose areound the website. Read the small tutorial. Open up the HTML manual and read the General entry first where it talks about permission to use and about installation. Then go to the entries on the Assembler, the (Motorola) Mot Syntax Module, the TOS output module, and the m68k CPU module, in particular, and read those. Then read the build instructions.

Then download the latest release source to someplace like "~asmwork/vasm/" and unpack and build it.

In brief,

  • Go to the directory that unpacking the tarball created and do a directory listing. Note all the makefiles.
  • Run make without arguments:
         $ make
    Ignore the feedback.
  • Now run
         $ make CPU=m68k SYNTAX=mot
  • Do a listing
         $ ls -lart
    and check that vasmm68k_mot has been built.
  • Link it into your local user file system's binary directory.

Given the example directory structure I've been mentioning, that last step can be done with something like 

 ln -s /home/me/asmwork/vasm/vasm/vasm68k_mot /home/me/prg/

Now we want our sample program that accumulates a few sums. This time we'll have to actually put it in a file instead of editing it interactively in the simulator.

Here's the code again, with stuff that's necessary for vasm and for the Atari ST target, and a little extra code inspired by the extra we did with the 6801:

	OPT LIST,SYMTAB	; Options we want for the stand-alone assembler.
	MACHINE MC68000	; because there are a lot the assembler can do.
	OPT DEBUG	; We want the debugger to know our labels.
	OUTPUT
***********************************************************************
	EVEN		; Just for good measure -- 68K needs code even aligned.
EXAMPLE:
	MOVEQ	#8,D0	; MOVEQ lets us ignore register width.
	ADDQ	#5,D0	; Default register width is okay.
	ADDQ	#2,D0	; D0 is comparable to 6800 A? Sort-of? Maybe?
	ADDQ	#7,D0
	ADDQ	#4,D0
	NOP		; one landing pad
RESTART:
	MOVE.W	#2056,D0	; the extra example for 6801
	ADD.W	#1285,D0
	ADD.W	#514,D0
	ADD.W	#1799,D0
	ADD.W	#1028,D0
	NOP		; two landing pad
DRESTART:
	MOVE.L	#134744072,D0	; 32-bit version
	ADD.L	#84215045,D0
	ADD.L	#33686018,D0
	ADD.L	#117901063,D0
	ADD.L	#67372036,D0
	NOP			; three landing pad
DONE:
	NOP			; You must "quit" the debugger.
	NOP			; Don't continue.

	END	EXAMPLE

In your host OS, copy that into an empty text editor document and save it in your working directory for the primer code as something like sum85274.s. Given the above structure, that would be  

~/asmwork/share/hatari/C/primer/sum85274.s

Drag the corner of your terminal shell window to widen it to mostly fill the screen before you continue. It'll make it easier to shift back to the terminal when you start debugging.

Assemble the file you just saved with vasm using the vasmm68k_mot command with parameters as follows:

$ vasmm68k_mot -Ftos -o SUM85274.PRG -L sum85274.lst sum85274.s

You can open the assembly listing file, sum85274.lst, in a text editor, to look at the results. 

If there are no errors, start Hatari there in the primer working directory:

$ hatari

When the desktop comes up, hit Ctrl-Z to bring up EmuCON. In EmuCON, change to the primer working directory, whatever you named it.

Then hit Alt-PAUSE to enter the debugger.

That's the alt key, with the PAUSE function key that is usually above the ten-key pad on a long keyboard, or at the top-right corner of the notebook PC keyboard. If you are working on a notebook computer, you probably need to hold down the Fn key while you hit Alt-PAUSE.

Sometimes, my computer seems to miss the Alt key and just pauses. If that happens, you may have to hit Alt-PAUSE again to enter the debugger.

When you enter the debugger, the emulated Atari screen may see some pixel folding. That's okay, ignore it. 

Move the host OS cursor over to the terminal shell window where you started Hatari, and click that window to bring it forward:

 

At this point, you're debugging the Atari ST operating system itself, or perhaps EmuCON.

----------------------------------------------------------------------
You have entered debug mode. Type c to continue emulation, h for help.

CPU=$e1d7e2, VBL=790, FrameCycles=128, HBL=0, LineCycles=128, DSP=N/A
00e1d7e2 46c0                     move.w d0,sr
>

Let's try the help command, just to see what help it gives us:

> h

Generic commands:
           cd (  ) : change directory
     evaluate ( e) : evaluate an expression
         help ( h) : print help
      history (hi) : show last CPU/DSP PC values & executed instructions
         info ( i) : show machine/OS information
         lock (  ) : specify information to show on entering the debugger
      logfile ( f) : set (memdump/disasm/etc) log file
        parse ( p) : get debugger commands from file
       rename (  ) : rename given file
        reset (  ) : reset emulation
   screenshot (  ) : save screenshot to given file
       setopt ( o) : set Hatari command line and debugger options
    stateload (  ) : restore emulation state
    statesave (  ) : save emulation state
        trace ( t) : select Hatari tracing settings
    variables ( v) : List builtin symbols / variables
         quit ( q) : quit emulator

CPU commands:
      address ( a) : set CPU PC address breakpoints
   breakpoint ( b) : set/remove/list conditional CPU breakpoints
       disasm ( d) : disassemble from PC, or given address
      profile (  ) : profile CPU code
       cpureg ( r) : dump register values or set register to value
      memdump ( m) : dump memory
     memwrite ( w) : write bytes/words/longs to memory
      loadbin ( l) : load a file into memory
      savebin (  ) : save memory to a file
      symbols (  ) : load CPU symbols & their addresses
         step ( s) : single-step CPU
         next ( n) : step CPU through subroutine calls / to given instruction type
         cont ( c) : continue emulation / CPU single-stepping

DSP commands:
   dspaddress (da) : set DSP PC address breakpoints
     dspbreak (db) : set/remove/list conditional DSP breakpoints
    dspdisasm (dd) : disassemble DSP code
   dspmemdump (dm) : dump DSP memory
   dspsymbols (  ) : load DSP symbols & their addresses
   dspprofile (dp) : profile DSP code
       dspreg (dr) : read/write DSP registers
      dspstep (ds) : single-step DSP
      dspnext (dn) : step DSP through subroutine calls / to given instruction type
      dspcont (dc) : continue emulation / DSP single-stepping

If value is prefixed with '$', it's a hexadecimal, if with '#', it's
a normal decimal, if with '%', it's a binary decimal. Prefix can
be skipped for numbers in the default number base (currently 10).

Any expression given in quotes (within ""), will be evaluated
before given to the debugger command.  Any register and symbol
names in the expression are replaced by their values.

Note that address ranges like '$fc0000-$fc0100' should have no
spaces between the range numbers.

'help <command>' gives more help.
>

You can try various commands, like disassembling code (d), dumping memory (m), and looking at registers (r). But don't try setting memory or registers just yet. 

If you do, you'll want to use the quit (q) command and start Hatari up again fresh. 

The problem you might be wondering about is how to get the target program into memory where you can debug it. I think it might be possible to use the debugger's load command (l), but, if so, I haven't figured that out yet.

Instead, as described in the debugger manual entry on breakpoints and variables, set a breakpoint to stop emulation after a program is loaded and before it is run with this break command: 

b pc = TEXT :once

Here's what it looks like typed in, with the results it displays:

> b pc = TEXT :once
CPU condition breakpoint 1 with 1 condition(s) added:
	pc = TEXT
-> Break only once, and delete breakpoint afterwards.
>

What that means is that it set a one-time breakpoint for the next time the PC is equal to the beginning of the TEXT segment. CP/M programs are started by starting execution at the beginning of the program's TEXT segment, so this will do what we want, if we make sure that the next program we run is the target program.

Use the continue command (c) to let Hatari continue running,

> c
Returning to emulation...

 and then bring the Hatari window back in front using the task bar or whatever. EmuCON should be showing you an active prompt there. 

At the prompt, type the name of the executable file that you just used vasmm68k_mot to create. If you used the same names as I did, above, that would be 

C:\primer>SUM85274.PRG

 with or without the .PRG extension, really.

Now use the task bar or whatever to get back to the console where the debugger will be showing you all sorts of things about the breakpoint, showing you the first instruction in the TEXT segment disassembled, and prompting you again:

1. CPU breakpoint condition(s) matched 1 times.
	pc = TEXT :once
Removed CPU breakpoint 1:
	pc = TEXT :once
Reading symbols from program '/home/nova/usr/share/hatari/C:/primer/SUM85274.PRG' symbol table...
TOS executable, DRI / GST symbol table, reloc=0, program flags: PRIVATE (0x0)
Program section sizes:
  text: 0xc, data: 0x0, bss: 0x0, symtab: 0xe
Trying to load DRI symbol table at offset 0x28...
Offsetting BSS/DATA symbols from TEXT section.
Skipping duplicate address & symbol name checks when autoload is enabled.
Loaded 1 symbols (1 TEXT) from '/home/nova/usr/share/hatari/C:/primer/SUM85274.PRG'.

CPU=$13d10, VBL=20873, FrameCycles=241160, HBL=237, LineCycles=368, DSP=N/A
00013d10 7008                     moveq #$08,d0
>

Notice that disassembly of the first instruction at the end of all that. We're ready to do a MOVEQ, ready to load D0 with the value 8.

We can do a disassembly, and the debugger will just assume, since we haven't done a disassembly during this session yet, that we want to see what the current PC is pointing out:

> d
(PC)
EXAMPLE:
00013d10 7008                     moveq #$08,d0
00013d12 5a40                     addq.w #$05,d0
00013d14 5440                     addq.w #$02,d0
00013d16 5e40                     addq.w #$07,d0
00013d18 5840                     addq.w #$04,d0
00013d1a 4e71                     nop 
RESTART:
00013d1c 303c 0808                move.w #$0808,d0
00013d20 d07c 0505                add.w #$0505,d0
00013d24 d07c 0202                add.w #$0202,d0
00013d28 d07c 0707                add.w #$0707,d0
00013d2c d07c 0404                add.w #$0404,d0
00013d30 4e71                     nop 
DRESTART:
00013d32 203c 0808 0808           move.l #$08080808,d0
00013d38 d0bc 0505 0505           add.l #$05050505,d0
00013d3e d0bc 0202 0202           add.l #$02020202,d0
00013d44 d0bc 0707 0707           add.l #$07070707,d0
00013d4a d0bc 0404 0404           add.l #$04040404,d0
00013d50 4e71                     nop 
00013d52 4e71                     nop 
>

Let's do a second disassembly to see if it has shown us all of the code. This time, it will pick up at where it left off:

> d
00013d54 0000 0000                or.b #$00,d0
00013d58 0000 0000                or.b #$00,d0
00013d5c 0000 0000                or.b #$00,d0
00013d60 0000 0000                or.b #$00,d0
00013d64 0000 0000                or.b #$00,d0
00013d68 0000 0000                or.b #$00,d0
00013d6c 0000 0000                or.b #$00,d0
00013d70 0000 0000                or.b #$00,d0
00013d74 0000 0000                or.b #$00,d0
00013d78 0000 0000                or.b #$00,d0
00013d7c 0000 0000                or.b #$00,d0
00013d80 0000 0000                or.b #$00,d0
00013d84 0000 0000                or.b #$00,d0
00013d88 0000 0000                or.b #$00,d0
00013d8c 0000 0000                or.b #$00,d0
00013d90 0000 0000                or.b #$00,d0
00013d94 0000 0000                or.b #$00,d0
00013d98 0000 0000                or.b #$00,d0
00013d9c 0000 0000                or.b #$00,d0
00013da0 0000 0000                or.b #$00,d0
00013da4 0000 0000                or.b #$00,d0
00013da8 0000 0000                or.b #$00,d0
00013dac 0000 0000                or.b #$00,d0
>

Yep, when there's nothing in memory, there's usually a lot of zeroes or a lot of garbage. And zeroes just happen to be the op-code for a byte-sized OR of immediate 0 into D0.

Try single stepping (s):

> s   

CPU=$13d12, VBL=32348, FrameCycles=35072, HBL=34, LineCycles=528, DSP=N/A
00013d12 5a40                     addq.w #$05,d0
>

Unfortunately, it doesn't show you which register(s) changed. It does show you the CPU and the next op-code, disassembled, along with a lot of display controller stuff. We want to see the registers, so, let's use the register command (r):

> r
  D0 00000008   D1 00000000   D2 00000000   D3 00000000 
  D4 00000000   D5 00000000   D6 00000000   D7 00000000 
  A0 00000000   A1 00000000   A2 00000000   A3 00000000 
  A4 00013D54   A5 00013D54   A6 00077FC6   A7 00077FF8 
USP  00077FF8 ISP  00007E64 
T=00 S=0 M=0 X=0 N=0 Z=0 V=0 C=0 IMASK=3 STP=0
Prefetch 5a40 (ADD) 5440 (ADD) Chip latch 00000000
00013d12 5a40                     addq.w #$05,d0
Next PC: 00013d14
>

So, if you step (s) and then show (r) the registers, you can watch the numbers add up (in hexadecimal) in data register D0.

> s

CPU=$13d14, VBL=32348, FrameCycles=35076, HBL=34, LineCycles=532, DSP=N/A
00013d14 5440                     addq.w #$02,d0
> r
  D0 0000000D   D1 00000000   D2 00000000   D3 00000000 
  D4 00000000   D5 00000000   D6 00000000   D7 00000000 
  A0 00000000   A1 00000000   A2 00000000   A3 00000000 
  A4 00013D54   A5 00013D54   A6 00077FC6   A7 00077FF8 
USP  00077FF8 ISP  00007E64 
T=00 S=0 M=0 X=0 N=0 Z=0 V=0 C=0 IMASK=3 STP=0
Prefetch 5440 (ADD) 5e40 (ADD) Chip latch 00000000
00013d14 5440                     addq.w #$02,d0
Next PC: 00013d16
> s

CPU=$13d16, VBL=32348, FrameCycles=35080, HBL=34, LineCycles=536, DSP=N/A
00013d16 5e40                     addq.w #$07,d0
> r
  D0 0000000F   D1 00000000   D2 00000000   D3 00000000 
  D4 00000000   D5 00000000   D6 00000000   D7 00000000 
  A0 00000000   A1 00000000   A2 00000000   A3 00000000 
  A4 00013D54   A5 00013D54   A6 00077FC6   A7 00077FF8 
USP  00077FF8 ISP  00007E64 
T=00 S=0 M=0 X=0 N=0 Z=0 V=0 C=0 IMASK=3 STP=0
Prefetch 5e40 (ADD) 5840 (ADD) Chip latch 00000000
00013d16 5e40                     addq.w #$07,d0
Next PC: 00013d18
> s

CPU=$13d18, VBL=32348, FrameCycles=35084, HBL=34, LineCycles=540, DSP=N/A
00013d18 5840                     addq.w #$04,d0
> r
  D0 00000016   D1 00000000   D2 00000000   D3 00000000 
  D4 00000000   D5 00000000   D6 00000000   D7 00000000 
  A0 00000000   A1 00000000   A2 00000000   A3 00000000 
  A4 00013D54   A5 00013D54   A6 00077FC6   A7 00077FF8 
USP  00077FF8 ISP  00007E64 
T=00 S=0 M=0 X=0 N=0 Z=0 V=0 C=0 IMASK=3 STP=0
Prefetch 5840 (ADD) 4e71 (NOP) Chip latch 00000000
00013d18 5840                     addq.w #$04,d0
Next PC: 00013d1a
> s

CPU=$13d1a, VBL=32348, FrameCycles=35088, HBL=34, LineCycles=544, DSP=N/A
00013d1a 4e71                     nop 
> r
  D0 0000001A   D1 00000000   D2 00000000   D3 00000000 
  D4 00000000   D5 00000000   D6 00000000   D7 00000000 
  A0 00000000   A1 00000000   A2 00000000   A3 00000000 
  A4 00013D54   A5 00013D54   A6 00077FC6   A7 00077FF8 
USP  00077FF8 ISP  00007E64 
T=00 S=0 M=0 X=0 N=0 Z=0 V=0 C=0 IMASK=3 STP=0
Prefetch 4e71 (NOP) 303c (MOVE) Chip latch 00000000
00013d1a 4e71                     nop 
Next PC: 00013d1c
>

Exciting, isn't it?

 Just don't step past the end of code!!!!!!!

Heh. Actually, it's not a problem, as long as you don't step too far. All those 
   OR #0,D0 

instructions don't really do much. They just really aren't very interesting.

But once you've stepped through the end of the code, then what? 

If you try to continue executing code that isn't there, something bad will eventually happen, right?

Sort, of. You'll get a segment error or a bus error or some such, and EmuTOS will try to catch you and send you back to the EmuCON window or something. But we can't guarantee that Hatari is in a stable state. (It's almost guaranteed for this one, but not quite.) So, instead, once you've stepped through all the code and convinced yourself it's doing what it's doing, just use the quit command (q) again and quit the Hatari session.

We'll look at how to get the program to safely return to the OS later, among other things

And that should get us started for working on the 68000.

Amiga emulators would also be interesting, but the Amiga run-time has some complexities that I don't want to deal with. Likewise the classic Macintosh systems. 

I'm not saying don't try them. Do, if you are inclined. They're fun, but distracting. MAME, too. MAME is really distracting.

I really wish I had time to write an open-source emulator for the MEX68KECB single board.  That would be the least distracting for this level of code.

Just for the record, MDOS for the EXORciser is approximately what TOS (and EmuTOS) for the Atari is. If the debugger for Hatari were able to assemble code interactively, we would not need, at this level, to be saving code in files and so forth on the Hatari. 

But we will get there before we are done. Don't worry.

I think we can get Hatari to do the job we need.

Next, I think I want to show you one way to separate the numbers we're adding in this example from the code itself.


(Title Page/Index)

 

Saturday, June 22, 2024

ALPP 01-04 -- Getting a Simulator for the 6801 and Running Code on It

Getting a Simulator for the 6801
and Running Code on It

(Title Page/Index)

 

I'll assume that you've already gone through the steps for getting the necessary operating system environment and tools, and have got EXORsim up and running, and have tested it with the example I gave showing how to use the accumulator to accumulate a sum of a series of constants.

Several years back, I needed (wanted?) a nice debug system for developing some 6801 code. At the time I started the project (if I recall correctly) Ciaran and his friends had not yet added MC-10 emulation to XRoar. Or maybe I didn't want to jump through the hoops of a self-hosted debugger on it. Or something.

An option I considered was to write my own 6801 simulator (a project I had already shown myself I didn't have the discipline to take to completion) or get enough of the documentation for the M6801 USE module for the EXORciser and the MC6801 EXORciser Support System to add that module to Joe Allen's EXORsim. But that latter begged the question of where to get the documentation, and whether I could afford the persuasion rate if I could find someone who had it.

A less ambitious option would be to write an alternative reality main CPU module for EXORsim, from a world in which Motorola had made the bare 6801 core available as a direct substitute for the 6800 -- in other words, with no built-in IO or RAM. It could be invoked as exor01, just as the 6809 version of EXORsim is invoked as exor09. That would allow me (and you) to use git to pull in Joe's updates without (too much) conflict with my  6801 tools. 

Just for the record, the timing differences might have meant MDOS and other system-level software wouldn't run on the 6801 simulation, even if you cleared the built-in I/O devices out the memory map.

I just wanted to run code, didn't care about timing, didn't know at the time how Joe would implement the 6809 modules, etc. So I simply made a fork of the EXORsim project (allowed by the GPL license) and added 6801 instructions (without attention to timing) to the 6800 instruction set, with a command-line switch to enable 6801 instructions. It worked for my project, and that is what I'm going to recommend you use for the 6801 here -- for now.

Which is going to take a little extra explanation.

Now, for the accumulator example, the 6801 code and execution will be exactly the same as for the 6800, so it might be tempting to skip it. But you'll need the explanation of how to get, compile, and use the EXORsim6801 tools, so we won't. And we can talk a little about 8-bit bytes vs. 16-bit words while we are at it.

EXORsim6801

There was a local code repository provider here called sourceforge.jp, and I started using them because they are local. They changed their name to Open Source Developers' Network (osdn.net) about the time SourceForge changed hands and started going a little crazy, so I started using OSDN as my main repository provider. Things have changed more since then, with some of SourceForge's original owners being able to buy it back, and all. And OSDN's team has not been able to keep it the easy-to-use place it was. And Microsoft bought Github. Etc. 

Excuses, what-ifs, and excuses, but EXORsim6801 is in my personal chambers (workspaces) on OSDN, here:

https://osdn.net/users/reiisi/pf/exorsim6801/wiki/FrontPage

It takes patience to access sometimes. If you get a timeout or a gateway error, refresh it, stop it, and refresh again, and it should come up, although, if it still doesn't come up, you may need to wait an hour or three, or a day, and try again.

I kept it in a chamber workspace because I intended to give the code back to Joe. He then told me he didn't really see the point, since it didn't reflect any real retro computing hardware or software that ever existed -- which is not unreasonable. 

If I make a real alternate reality project out of it, I should at least get the timing right, and make it a separate executable so I can pull in his updates. But that will take time I don't have.

You can read my summary from back then, and then go to the source code menu and select "source tree", or you can go directly to the source tree here:

https://osdn.net/users/reiisi/pf/exorsim6801/scm/tree/master/

On the right of the source tree page, towards the top, you'll find the git URL for cloning, and ZIP and TAR buttons for export. Hit your choice of ZIP or TAR (.tar.gz) to download, or use the git clone command to get your copy.

You should probably want to clone it or unpack the archive in a directory called exor6801 under your assembly language working directory (as in "~/asmwork/exor6801"), or use some other clear structure to keep it separate from Joe's exorsim.

After cloning or unpacking, change into the source code directory produced and do NOT do a "sudo make install"! 

Just do a "make", without sudo and without install. 

If you want to make it available without the path, when it's built, you can link it into your executable directory under a different name, such as "exorprime" or something.

But for what we want to do for the present, we can work directly in the build directory. So, in the build directory, basically do the same as you did for the 6800, except this time you'll invoke exor with two switches:

./exor --6801 --mon

Other than that, the session should look pretty much like the 6800 session:

$ cd asmwork/exorsim6801/exorsim
$ ./exor --mon --6801
Load facts file 'facts'
'exbug.bin' loaded.
'mdos.dsk' opened for drive 0 (single sided)

Hit Ctrl-C for simulator command line.  Starting simulation...

>         0 A=00 B=00 X=0000 SP=FF8A ------ OSLOAD   E800: 8E FF 8A LDS #$FF8A                Load OS

Type 'help'
% a 1000
1000: START LDAA	#8	; Gotta start somewhere.
1002:  ADDA	#5
1004:  ADDA	#2
1006:  ADDA	#7
1008:  ADDA	#4
100a:  NOP		; landing pad for breakpoint
100b: 
% u 1000
1000: 86 08               LDA #$08
1002: 8B 05               ADDA #$05
1004: 8B 02               ADDA #$02
1006: 8B 07               ADDA #$07
1008: 8B 04               ADDA #$04
100A: 01                  NOP
100B: 00                  ???
100C: 00                  ???
...
% d 1000
1000: 86 08 8B 05 8B 02 8B 07  8B 04 01 00 00 00 00 00 ................
1010: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 ................
...
% s 1000
          0 A=00 B=00 X=0000 SP=FF8A ------ START    1000: 86 08    LDA #08   EA=1001 D=08   
>         1 A=08 B=00 X=0000 SP=FF8A ------          1002: 8B 05    ADDA #05                 

Type 'help'
% s
          1 A=08 B=00 X=0000 SP=FF8A ------          1002: 8B 05    ADDA #05  EA=1003 D=05   
>         2 A=0D B=00 X=0000 SP=FF8A ------          1004: 8B 02    ADDA #02                 

Type 'help'
% s
          2 A=0D B=00 X=0000 SP=FF8A ------          1004: 8B 02    ADDA #02  EA=1005 D=02   
>         3 A=0F B=00 X=0000 SP=FF8A ------          1006: 8B 07    ADDA #07                 

Type 'help'
% s
          3 A=0F B=00 X=0000 SP=FF8A ------          1006: 8B 07    ADDA #07  EA=1007 D=07   
>         4 A=16 B=00 X=0000 SP=FF8A H-----          1008: 8B 04    ADDA #04                 

Type 'help'
% s
          4 A=16 B=00 X=0000 SP=FF8A H-----          1008: 8B 04    ADDA #04  EA=1009 D=04   
>         5 A=1A B=00 X=0000 SP=FF8A ------          100A: 01       NOP                      

Type 'help'
% b 100a
Breakpoint set at 100A
% c 1000

Breakpoint!
          0 A=00 B=00 X=0000 SP=FF8A ------ START    1000: 86 08    LDA #08   EA=1001 D=08   
          1 A=08 B=00 X=0000 SP=FF8A ------          1002: 8B 05    ADDA #05  EA=1003 D=05   
          2 A=0D B=00 X=0000 SP=FF8A ------          1004: 8B 02    ADDA #02  EA=1005 D=02   
          3 A=0F B=00 X=0000 SP=FF8A ------          1006: 8B 07    ADDA #07  EA=1007 D=07   
          4 A=16 B=00 X=0000 SP=FF8A H-----          1008: 8B 04    ADDA #04  EA=1009 D=04   
          5 A=1A B=00 X=0000 SP=FF8A ------ START    1000: 86 08    LDA #08   EA=1001 D=08   
          6 A=08 B=00 X=0000 SP=FF8A ------          1002: 8B 05    ADDA #05  EA=1003 D=05   
          7 A=0D B=00 X=0000 SP=FF8A ------          1004: 8B 02    ADDA #02  EA=1005 D=02   
          8 A=0F B=00 X=0000 SP=FF8A ------          1006: 8B 07    ADDA #07  EA=1007 D=07   
          9 A=16 B=00 X=0000 SP=FF8A H-----          1008: 8B 04    ADDA #04  EA=1009 D=04   
>        10 A=1A B=00 X=0000 SP=FF8A ------          100A: 01       NOP                      

Type 'help'
% t on
% c 1000
         10 A=1A B=00 X=0000 SP=FF8A ------ START    1000: 86 08    LDA #08   EA=1001 D=08   
         11 A=08 B=00 X=0000 SP=FF8A ------          1002: 8B 05    ADDA #05  EA=1003 D=05   
         12 A=0D B=00 X=0000 SP=FF8A ------          1004: 8B 02    ADDA #02  EA=1005 D=02   
         13 A=0F B=00 X=0000 SP=FF8A ------          1006: 8B 07    ADDA #07  EA=1007 D=07   
         14 A=16 B=00 X=0000 SP=FF8A H-----          1008: 8B 04    ADDA #04  EA=1009 D=04   

Breakpoint!
>        15 A=1A B=00 X=0000 SP=FF8A ------          100A: 01       NOP                      

Type 'help'
%   

This older version likes to give you traceback after a breakpoint, if tracing is off. You can ignore it or examine it, as you like.

But that was all a bit boring since you've done it before, twice, so, before you hit control-C to break out, let's try adding a little code that does not assemble or  run on the 6800, just to be sure we actually have the 6801 emulator running. Go ahead and type this in by hand. It's not long:

% a 100b
100b: DSTART LDD #2056
100e:  ADDD #1285
1011:  ADDD #514
1014:  ADDD #1799
1017:  ADDD #1028
101a:  NOP
101b: 

Hit enter at the blank line to quit assembling, and then display the bytes and disassemble it:

% d 1000
1000: 86 08 8B 05 8B 02 8B 07  8B 04 01 CC 08 08 C3 05 ................
1010: 05 C3 02 02 C3 07 07 C3  04 04 01 00 00 00 00 00 ................
1020: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 ................
...
% u 1000
1000: 86 08               LDA #$08
1002: 8B 05               ADDA #$05
1004: 8B 02               ADDA #$02
1006: 8B 07               ADDA #$07
1008: 8B 04               ADDA #$04
100A: 01                  NOP
100B: CC 08 08            LDD #$0808
100E: C3 05 05            ADDD #$0505
1011: C3 02 02            ADDD #$0202
1014: C3 07 07            ADDD #$0707
1017: C3 04 04            ADDD #$0404
101A: 01                  NOP
101B: 00                  ???
101C: 00                  ???

You see that my choice of numbers to add was deliberate, right?

Set the break point at $101A  and set trace on, then restart execution at $1000:

% b 101a
Breakpoint set at 101A
% t on
% c 1000
         39 A=1A B=1A X=0000 SP=FF8A ------ START    1000: 86 08    LDA #08   EA=1001 D=08   
         40 A=08 B=1A X=0000 SP=FF8A ------          1002: 8B 05    ADDA #05  EA=1003 D=05   
         41 A=0D B=1A X=0000 SP=FF8A ------          1004: 8B 02    ADDA #02  EA=1005 D=02   
         42 A=0F B=1A X=0000 SP=FF8A ------          1006: 8B 07    ADDA #07  EA=1007 D=07   
         43 A=16 B=1A X=0000 SP=FF8A H-----          1008: 8B 04    ADDA #04  EA=1009 D=04   
         44 A=1A B=1A X=0000 SP=FF8A ------          100A: 01       NOP                      
         45 A=1A B=1A X=0000 SP=FF8A ------ DSTART   100B: CC 08 08 LDD #$0808 EA=100C D=0808 
         46 A=08 B=08 X=0000 SP=FF8A ------          100E: C3 05 05 ADDD #$0505 EA=100F D=0505 
         47 A=0D B=0D X=0000 SP=FF8A ------          1011: C3 02 02 ADDD #$0202 EA=1012 D=0202 
         48 A=0F B=0F X=0000 SP=FF8A ------          1014: C3 07 07 ADDD #$0707 EA=1015 D=0707 
         49 A=16 B=16 X=0000 SP=FF8A ------          1017: C3 04 04 ADDD #$0404 EA=1018 D=0404 

Breakpoint!
>        50 A=1A B=1A X=0000 SP=FF8A ------          101A: 01       NOP                      

Type 'help'
% 

Notice what's happening in the accumulators. 

(This additional code, by the way, also runs on the 6809.)

******

Ah. Yes. I need to mention this. 

You may be wondering, when loading integer constants into the double accumulator on the 6801 and 6809, which accumulator gets the more significant byte? It's not apparent in this code, but, in both, A gets the more significant byte and B gets the less significant byte. 

This can be confusing when reading early code for the 6800, because the 6800 was apparently designed under the opposite assumption. Check the stacking order of interrupts. On both the 6800 and the 6801, A gets pushed before B, which results in B being saved lower in memory, where the most significant byte should be. And much of the code written for the 6800, including the EXORciser EXBug monitor ROM, follows the same order, with B holding the more significant byte in two-byte operations, and being stored lower in memory.

But when loading two-byte integers into D on either the 6809 or the 6801, B gets the less significant byte and A gets the more significant byte.

The push order is fixed on the 6809, by the way.

Trivia, but not trivia.

******

This should motivate our discussion of hexadecimal, and of the limits of sizes of integers within the CPU. Play around with it, or hang on to your questions for now, either way.

Again, there are other options, including XRoar or MAME emulating Tandy's MC-10 (which actually has a 6803, but that's just a 6801 without internal ROM). Also, for MSWindows, users, VMC10 can be found in the Color Computer Archives

If you decide to use XRoar or MAME or VMC10 or such, you'll also need self-hosted tools like HumBug and MCOS, which can also be found in the Color Computer Archives. And, if I remember right, the syntax will be a little different, so you'll have to figure that out. (It's not hard once you have the basic ideas down.)

And all that discussion should get us a little bit more ready to go after Hatari for working on the 68000.

 

(Title Page/Index)

 

Sunday, June 16, 2024

ALPP 01-03 -- Running Code on the 6800 and 6809

 Running Code on the
6800 and 6809

(Title Page/Index)

 

Now that you have EXORsim running on your workstation, let's look at how you can use it to run some code.

If you shut down after working through the last post, boot back up and change directory to get back in the directory you built EXORsim in, doing something like

$ cd asmwork/exor/exorsim

In the directory where you built EXORsim, start it up with the --mon option.

$ ./exor --mon
Load facts file 'facts'
'exbug.bin' loaded.
  EXBUG-1.1 detected
'mdos.dsk' opened for drive 0 (double sided)

OSLOAD...

Hit Ctrl-C for simulator command line.  Starting simulation...

>         0 A=00 B=00 X=0000 SP=00FF ------          0020: B6 E8 00 LDA E800                 

6800 Monitor: Ctrl-C to exit, 'c' to continue, or type 'help'
% 

We can start with the 6800 example showing how an accumulator works. The 6800 code, again:

START LDAA	#8	; Gotta start somewhere.
 ADDA	#5
 ADDA	#2
 ADDA	#7
 ADDA	#4
 NOP		; landing pad for breakpoint 

Select it from the START label and copy it to the end of the NOP line.

At the % prompt in the debugger, type 

a 1000

and enter/return. 

You could type it in by hand, but since you've just selected and copied it, just paste it in. Use the right button on the mouse to pull up an edit menu over the session window and paste it. Hit enter again after the paste:

% a 1000
1000: START LDAA	#8	; Gotta start somewhere.
1002:  ADDA	#5
1004:  ADDA	#2
1006:  ADDA	#7
1008:  ADDA	#4
100a:  NOP		; landing pad for breakpoint 
100b: 
% 

What have you done?

The "a" command is the assemble command. Joe put the ability to assemble source code into the hosted debugger. (Thanks, Joe!) So you've just assembled the source code of the example into memory starting at hexadecimal $1000.

You can unassemble it if you want, with the "u" command:

% u 1000
1000: 86 08               LDA #$08
1002: 8B 05               ADDA #$05
1004: 8B 02               ADDA #$02
1006: 8B 07               ADDA #$07
1008: 8B 04               ADDA #$04
100A: 01                  NOP
100B: 00                  ???
100C: 00                  ???
...

Unassemble, disassemble, same thing. 

Note that the address specified for the debugger commands is read by the debugger as hexadecimal. (Values in the assembler itself are default decimal.)

You can display the contents of memory where you assembled it with the "d 1000" command:

% d 1000
1000: 86 08 8B 05 8B 02 8B 07  8B 04 01 00 00 00 00 00 ................
1010: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 ................
...

Now you know why it's "u" for unassemble instead of "d" for disassemble. "d" is for display. (Or dump, if you prefer, but dump can mean other things.)

How do you run it? One way is to use the "s" command, for step:

% s 1000

          0 A=00 B=00 X=0000 SP=00FF ------ START    1000: 86 08    LDA #08   EA=1001 D=08   
>         1 A=08 B=00 X=0000 SP=00FF ------          1002: 8B 05    ADDA #05                 

6800 Monitor: Ctrl-C to exit, 'c' to continue, or type 'help'
% 

You'll see that it went to address $1000 and stepped one op-code, showing you the next op-code. And it's nice to see the op-codes disassembled. Unassembled.

Hit "s" all by itself and return and it steps the next one:

% s

          1 A=08 B=00 X=0000 SP=00FF ------          1002: 8B 05    ADDA #05  EA=1003 D=05   
>         2 A=0D B=00 X=0000 SP=00FF ------          1004: 8B 02    ADDA #02                 

6800 Monitor: Ctrl-C to exit, 'c' to continue, or type 'help'
% s

          2 A=0D B=00 X=0000 SP=00FF ------          1004: 8B 02    ADDA #02  EA=1005 D=02   
>         3 A=0F B=00 X=0000 SP=00FF ------          1006: 8B 07    ADDA #07                 

6800 Monitor: Ctrl-C to exit, 'c' to continue, or type 'help'
% s

          3 A=0F B=00 X=0000 SP=00FF ------          1006: 8B 07    ADDA #07  EA=1007 D=07   
>         4 A=16 B=00 X=0000 SP=00FF H-----          1008: 8B 04    ADDA #04                 

6800 Monitor: Ctrl-C to exit, 'c' to continue, or type 'help'
% s

          4 A=16 B=00 X=0000 SP=00FF H-----          1008: 8B 04    ADDA #04  EA=1009 D=04   
>         5 A=1A B=00 X=0000 SP=00FF ------          100A: 01       NOP                      

6800 Monitor: Ctrl-C to exit, 'c' to continue, or type 'help'
% 

And you can watch the effects -- watch the sum accumulate in the accumulator, and watch the program counter increment as it the simulator sequences through the op-codes.

If stepping is a little slow for you, you can set a breakpoint with the "b" command, and use the "c" command for continue, until it hits the breakpoint:

% b 100a
Breakpoint set at 100A
% c 1000


Breakpoint!
          9 A=16 B=00 X=0000 SP=00FF H-----          1008: 8B 04    ADDA #04  EA=1009 D=04   
>        10 A=1A B=00 X=0000 SP=00FF ------          100A: 01       NOP                      

6800 Monitor: Ctrl-C to exit, 'c' to continue, or type 'help'
% 

Note that the simulator's PC has to hit the exact breakpoint to stop. That's part of the reason I use the NOP as a landing pad. It's easier to see where to set the breakpoint.

But you wanted to see it trace through the operations, not just hum away in silence until it hit the breakpoint?

Use the "t" command to turn trace on:

% t on
% c 1000

         10 A=1A B=00 X=0000 SP=00FF ------ START    1000: 86 08    LDA #08   EA=1001 D=08   
         11 A=08 B=00 X=0000 SP=00FF ------          1002: 8B 05    ADDA #05  EA=1003 D=05   
         12 A=0D B=00 X=0000 SP=00FF ------          1004: 8B 02    ADDA #02  EA=1005 D=02   
         13 A=0F B=00 X=0000 SP=00FF ------          1006: 8B 07    ADDA #07  EA=1007 D=07   
         14 A=16 B=00 X=0000 SP=00FF H-----          1008: 8B 04    ADDA #04  EA=1009 D=04   

Breakpoint!
>        15 A=1A B=00 X=0000 SP=00FF ------          100A: 01       NOP                      

6800 Monitor: Ctrl-C to exit, 'c' to continue, or type 'help'
% 

Fortunately, the breakpoint was still set.

And you've probably noticed by now that there's a help command. Try it now, just for grins.

Okay, you've got the basics of the debugger in EXORsim down now, you can play around a bit. 

Go ahead and try things. If it gets hung up, you can always hit ctrl-C, and if that doesn't work, just close the shell session window and open a new one. 

How about the 6809?

Here's the 6809 code for the above:

START LDA	#8	; 6809 mnemonic: LoaD accumulator A
 ADDA	#5	; Mnemonic shared with 6800/6801.
 ADDA	#2
 ADDA	#7
 ADDA	#4 
 NOP		; landing pad for breakpoint 

 In EXORsim, it's not a whole lot different. The commands are the same. The main difference is the set of op-codes and their mnemonics. 

Oh, and the command to start it running is "exor09":

$ ./exor09 --mon
Load facts file 'facts09'
'exbug09.bin' loaded.
  EXBUG09-2.1 detected
'mdos09.dsk' opened for drive 0 (double sided)

OSLOAD...

Hit Ctrl-C for simulator command line.  Starting simulation...

>         0 A=00 B=00 X=0000 Y=0000 U=0000 S=00FF P=00 --------            0020: 86 10        LDA #$10                   

6809 Monitor: Ctrl-C to exit, 'c' to continue, or type 'help'
% 
Everything above looks pretty much the same for the code example above, except for the 6809's extra registers, for assembling, copying and pasting, disassembling, displaying, stepping, setting breakpoints, continuing, tracing:
% a 1000
1000: START LDA	#8	; 6809 mnemonic: LoaD accumulator A
1002:  ADDA	#5	; Mnemonic shared with 6800/6801.
1004:  ADDA	#2
1006:  ADDA	#7
1008:  ADDA	#4 
100a:  NOP		; landing pad for breakpoint 
100b: 
% u 1000
1000: 86 08               LDA #$08
1002: 8B 05               ADDA #$05
1004: 8B 02               ADDA #$02
1006: 8B 07               ADDA #$07
1008: 8B 04               ADDA #$04
100A: 12                  NOP 
100B: 00 00               NEG $00
100D: 00 00               NEG $00
...
% d 1000
1000: 86 08 8B 05 8B 02 8B 07  8B 04 12 00 00 00 00 00 ................
1010: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 ................
...
$ s 1000

         10 A=1A B=00 X=0000 Y=0000 U=0000 S=00FF P=00 -------- START      1000: 86 08        LDA #$08                   
>        11 A=08 B=00 X=0000 Y=0000 U=0000 S=00FF P=00 --------            1002: 8B 05        ADDA #$05                  

6809 Monitor: Ctrl-C to exit, 'c' to continue, or type 'help'
% s

         11 A=08 B=00 X=0000 Y=0000 U=0000 S=00FF P=00 --------            1002: 8B 05        ADDA #$05                  
>        12 A=0D B=00 X=0000 Y=0000 U=0000 S=00FF P=00 --------            1004: 8B 02        ADDA #$02                  

6809 Monitor: Ctrl-C to exit, 'c' to continue, or type 'help'
% s

         12 A=0D B=00 X=0000 Y=0000 U=0000 S=00FF P=00 --------            1004: 8B 02        ADDA #$02                  
>        13 A=0F B=00 X=0000 Y=0000 U=0000 S=00FF P=00 --------            1006: 8B 07        ADDA #$07                  

6809 Monitor: Ctrl-C to exit, 'c' to continue, or type 'help'
% s

         13 A=0F B=00 X=0000 Y=0000 U=0000 S=00FF P=00 --------            1006: 8B 07        ADDA #$07                  
>        14 A=16 B=00 X=0000 Y=0000 U=0000 S=00FF P=00 --H-----            1008: 8B 04        ADDA #$04                  

6809 Monitor: Ctrl-C to exit, 'c' to continue, or type 'help'
% s

         14 A=16 B=00 X=0000 Y=0000 U=0000 S=00FF P=00 --H-----            1008: 8B 04        ADDA #$04                  
>        15 A=1A B=00 X=0000 Y=0000 U=0000 S=00FF P=00 --------            100A: 12           NOP                        

6809 Monitor: Ctrl-C to exit, 'c' to continue, or type 'help'
%  
% b 100a
Breakpoint set at 100A
% c 1000


Breakpoint!
          4 A=16 B=00 X=0000 Y=0000 U=0000 S=00FF P=00 --H-----            1008: 8B 04        ADDA #$04                  
>         5 A=1A B=00 X=0000 Y=0000 U=0000 S=00FF P=00 --------            100A: 12           NOP                        

6809 Monitor: Ctrl-C to exit, 'c' to continue, or type 'help'
% t on
% c 1000

          5 A=1A B=00 X=0000 Y=0000 U=0000 S=00FF P=00 -------- START      1000: 86 08        LDA #$08                   
          6 A=08 B=00 X=0000 Y=0000 U=0000 S=00FF P=00 --------            1002: 8B 05        ADDA #$05                  
          7 A=0D B=00 X=0000 Y=0000 U=0000 S=00FF P=00 --------            1004: 8B 02        ADDA #$02                  
          8 A=0F B=00 X=0000 Y=0000 U=0000 S=00FF P=00 --------            1006: 8B 07        ADDA #$07                  
          9 A=16 B=00 X=0000 Y=0000 U=0000 S=00FF P=00 --H-----            1008: 8B 04        ADDA #$04                  

Breakpoint!
>        10 A=1A B=00 X=0000 Y=0000 U=0000 S=00FF P=00 --------            100A: 12           NOP                        

6809 Monitor: Ctrl-C to exit, 'c' to continue, or type 'help'
% 

So, give the 6809 code a try, too, looking for differences. 

Then take a rest  before proceeding to getting a simulator for the 6801.

 

(Title Page/Index)

 

Saturday, June 15, 2024

ALPP XX-XX -- Running Code on the 6800, 6801, 6809, and 68000

This chapter got scratched. Kept me spinning my wheels for a month or two. But I want to keep it around for my own reference. 

Running Code on the
M6800, 6801, and 6809

(Title Page/Index)

So, we want to run code, and we want to see the code run step-by-step.

If we had, for instance, Motorola's Micro Chroma 68 prototyping board, we could hand-assemble 6800 code and use the built-in debugging monitor to step through it. That is educational, and interesting, but those are hard to come by. (I theoretically may still have one in storage somewhere I can't access right now.) And hand-assembling code does take more time than using an assembler.

Similarly, Motorola had an evaluation board for the 68000, the MEX68KECB (Educational Board Computer), with a really nice debugging monitor in the ROM that assembled and disassembled code for you (that I probably should have bought way back when). Those ought to be easier to find, if still hard to get owners to part with, but when you search the web for them, you have to wade through a lot of retro devices that reproduce, with varying degrees of reliability, the original, or even just ride on the name. Some of those retro devices are interesting, but you have to know what you're looking at. 

If I had managed to save up enough to properly retire, I could be building a few retro projects of this sort myself, and could recommend them directly. (Sorry. That didn't happen.)

Motorola also made a full workstation for developing hardware and software for the 6800 and related parts called EXORciser. (Yes, I think it was a cool, but unfortunate, choice of name.) You could also put in a 6809 processor, for 6809 development. 

It was somewhat comparable to Intel's Intellec 8 systems, but reportedly more usable as a general purpose computer, comparable to the Altair 8800 and other S-100 systems. 

And they made a full workstation for developing for the 68000, called EXORMacs. 

But you probably won't be finding real examples of either of these to use in learning assembly language -- they are very rare now.

(Yeah, if I had the time and resources, it'd be fun to build retro replicas of both the EXORciser and EXORMacs, too.)

As an example of a home computer using the 6801, Tandy/Radio Shack's MC-10 (which actually uses the 6803 variant) is still sometimes seen on ebay and elsewhere, and is supported by an active enthusiast community (including a group on Facebook). Even though it's not really intended for learning assembly language, they'll help you gather up software and hardware to make it useful.

For the 6809, the Tandy/Radio Shack Color Computer is relative easy to find, and is also actively supported by an active (active, active!) community of enthusiasts (many of whom are also in the MC-10 community) who, again, will help you gather up software and hardware necessary to use it to learn assembly language. (Several groups on Facebook, here's one. Also, there's a mailing list that can help with both the Color Computer and the MC-10.)

The Color Computer's sister computer from the UK, the Dragon, is not easy to find, but the Dragon community is active, and generally participates in the Color Computer groups, too.

Other options exist, of course, like the SWTPC 6800 and 6809 models, also the French cousin to the MC-10, the Matra Alice. These are rather rare now. Even rarer are the Thomson line of French 6809-based computers and quite a number of Japanese computers (Fujitsu, Hitachi, and others) that used the 6800 and 6809.

If you look around and are careful about what you get, there are various retro designs that you can build yourself.

As I've noted, I don't really have room for hardware. If you don't either, you'll be glad to know that software emulators (simulators) are available that run on the kinds of PCs you are likely to already own. 

If you are running a Microsoft operating system (MSWindows), you'll be able to find several emulators with a fairly quick web search. Members of the support communities will tell you which they favor. I don't have experience with those, so I won't recommend any, but they can be found fairly easily, and are said to be good.

Also, there are several on-line 6809 emulators, but I don't want to encourage lots of people to jump on those and load them down.

One emulator I like that runs on my equipment is XRoar, developed primarily by the Dragon community's Ciaran Anscomb. It can currently emulate the Dragon, the Color Computer, the MC-10, and certain versions of the Alice. I like it as a simulator, it's fairly easy to get going and to maintain, and doesn't take up the room that the MAME monster takes up on your hard drive. And the important thing for me is that it can be compiled on Linux OSses.

One downside to XRoar is that it does not include a lot of hosted debugging tools. You have to find self-hosted debugging software, such as EDTASM+ for the Color Computer, which means additional layers to wade through. (I want to help Ciaran add hosted debugging, but so far we haven't been able to connect when both of us have had the time to get me started.)

Speaking of MAME, MAME emulation is pretty good, too. But it's big, and complicated, and I don't want to recommend it for the beginner. (I haven't even figured out how to get debugging going on MAME yet, myself.)

As you noticed, I use a Linux OS, and I will be using simulators that run on those, in particular, Joe H. Allen's  EXORsim. EXORsim was originally just for the 6800, but Joe has recently extended it to simulate the 6809 as the main processor as well.

There was a 6801 hosted development module (auxiliary card) for the EXORciser, but EXORsim does not simulate that. If I can find enough documentation and time, I may try adding support for it sometime. But not just now. 

Several years back, I wanted to do something with the 6801, and I had a little time, so I added some code to EXORsim to let the main processor execute the additional 6801 instructions. The cycle-by-cycle timing is 6800 instead of 6801, and I did not add simulation for the 6801's internal devices, but it allowed me to get a version of fig-Forth optimized for the 6801 running and somewhat tested, and even running on the MC-10. So I will use that for the 6801.

EXORsim can be compiled to run on MSWindows and on Modern Mac OS, so you may want to consider it for that, as well.

I wish I had time to write an EXORmacs simulator, for the 68000, or even to use musashi or Moira to build a prototyping board style simulator for the 68000 -- Maybe I can do that once I've put enough money away to properly retire, if there's anything left of my mind by then. 

That failing, for now I'm using the Atari ST emulator, Hatari, for this project. Unfortunately, that requires some compromises, compared with EXORsim, such as not being able to copy text output from the Hatari window with copy/paste. Screenshots, typing by hand, and disk files it will be.

So you may want to get EXORsim and Hatari to make it easier to follow along with me. These are the tools I will be referring to when I show code running on the 6800, 6801, 6809, and 68000. 

Hatari is available from repositories in many libre OSses.

In order to get EXORsim to run, you'll probably have to build it yourself. But it's not that hard, if you have fairly standard tools installed on the computer you are using as a workstation.

ALPP 01-02 -- Getting a Simulator for the 6800 and 6809

Getting a Simulator for the
6800 and 6809

(Title Page/Index)

 

Okay, so we've introduced assembly language by talking a little about adding small integers. But if we want to understand what's going on, we really need some way to watch what the processor does when it executes the code.

If I had more time and money, I would design my own hardware and build my own simulator software, and offer the hardware for sale and put the software up for download and all that, and it would all be real easy to use. (Of COURSE! ;-)

Fortunately, there are useful simulators (software-based emulators) already available, as I have mentioned. 

There are options other than the one I'm recommending, such as XRoar for the 6809 and 6801, which simulates the Dragon, the Tandy Color Computers 1, 2, and 3, and the Radio Shack MC-10, and the original Matra Alice 4K. If Ciaran doesn't beat me to it, I may try (again) to add hosted debugging to XRoar, but you can always run a self-hosted debugger (such as Disk EDTASM) on the emulated computer. 

Now, Ciaran and his friends do provide an on-line emulator, and you can download Disk EDTASM and run it on the on-line simulator, but I don't want to be encouraging lots of people to put a heavy load on Ciaran's server. 

I'll talk a little about getting XRoar and building it locally on your own hardware and using EDTASM for debugging later, but It's a pretty steep start-up for a topic that already has a steep learning curve.)

Similarly, VCC for MSWindows requires compiling (if I read the website right), and only emulates the Color Computer 3 (6809). I think I have heard that it supports direct debugging fairly well, but cannot vouch for that. It might be an option if you're running MSWindows. 

Both VCC and Xroar require several libraries that are themselves dependent on other libraries, so building them is not necessarily straightforward. I want to avoid that kind of mess as a requirement.

Yes, MAME would work, too, but it's huge. Just huge. I understand it provides hosted debugging, but I have not gotten that far with it yet. It does tend to be available on a number of common platforms.

So,

EXORciser

What I will use for 6800 and 6809 code, especially in the first part of this, will be Joe. H. Allen's EXORciser simulator, EXORsim

(I suppose the name, EXORciser, was a deliberate pun on Motorola's part. Both hardware and software needs exercising to find weak places, and sometimes debugging designs does seem to be a little like exorcising demons. But it does make searching for information on it a little difficult now. Looking for EXORsim, in particular, will find your search engine determined to tell you about exorcism, instead.)

The EXORciser was Motorola's 6800-based workstation microcomputer for developing both software and hardware for the 6800. It ran an operating system called MDOS provided by Motorola, along with applications supplied by Motorola and 3rd-party developers.

The EXORciser was a little expensive compared to popular microcomputers that came out shortly after, but it turned out to work well enough as a general purpose microcomputer to be used as an office computer, as well. Southwest Technical Products (SWTPC) and others released microcomputers based on, and somewhat compatible with the EXORciser, with less support for hardware development, but also less expensive.

When Motorola introduced the 6809, they developed a CPU board for it with the 6809 replacing the 6800, and the software was kept mostly compatible, not taking full advantage of the 6809's improved architecture.This allowed the same Exorciser hardware to be shared across projects using each processor.

EXORsim

Joe Allen's EXORsim simulates in software both the EXORciser, and the SWTPC 6800-based microcomputers. Recently, Joe added the 6809, so it can be used for both CPUs, as well.

EXORsim is very convenient, in that the simulated terminal allows you to copy and paste, simplifying the process of getting code and data into the simulated microcomputer. 

More importantly, it can be compiled easily on pretty much anything that supports ANSI C and a few of the basic POSIX libraries, which includes, well, lots of OSses and lots of compiler toolchains. In specific, you can definitely compile it on pretty much any Linux OS, Mac OS, or BSD OS, with the GNU compiler or CLang toolchains. You can also compile it on MSWindows with the Cygwin environment and compilers.

(It should be possible to get it working under Microsoft's LSW, but I don't want to take the time to verify that. If you go that route, save yourself some time and go ahead and load Ubuntu or openSUSE or whatever on top of LSW, and work in that.) 

You'll need the compilers and toolchains anyway, so you'll need to go ahead and get them now.

Old PCs running a Linux OS or BSD OS

If you aren't already using a Linux OS or Mac OS or freeBSD or netBSD, and you have an old (from even as long as 15 years ago) PC you aren't using, with 4 GB or more RAM, 40 GB or more of hard disk, and a CPU with at least two physical cores running faster than 1.2 GHz (or one core running faster than 2.5 GHz), you can save any data on it that you might need, wipe it clean, and install Devuan, Ubuntu, Debian, Mint OS, Cent OS, openSUSE, NetBSD, or FreeBSD or whatever on it.

(Note that openBSD may be a little too security-oriented to compile EXORciser and Hatari easily.)

Do remember to check it for important data before you do, and to back any important data up somewhere safe.

Or, if it has at least 80 GB free on the hard disk, you might be able to defragment it, resize the MSWindows partition, and install the Linux or BSD OS in a dual-boot configuration. It's still best to back up any important data first.

If the old PC is a little tighter for  resources than that, Ubuntu provides LUbuntu and XUbuntu that might fit, and Debian and the others can be configured with a light-weight window and desktop manager, and so forth.

While you're installing the OS, make sure you also install the C compilers, either GNU or CLang, and the POSIX libraries. (These should come along with any basic developers' environment option the distribution provides.) 

Also make sure you install a programmers' text editor, such as gedit, kate, geany, VIM, or eMacs. And a command-line terminal window emulator for running commands in, like Xterm. And if your choice of Linux OS has gforth in the repositories, you might want to grab that, too, but it isn't, strictly speaking, necessary.

Just for the record, I do not recommend dual-booting. You tend to avoid switching back and forth, so you tend not to do things that require switching.

If you're not dual-booting, installing a Linux OS is really not that hard.  FreeBSD or NetBSD will be a little on the difficult side for some people. They all have instructions on their sites oriented towards the technical level of people that the OS is geared towards, and these days it's relatively rare to run into exceptions in the install process. Look at the install instructions and pick one that feels comfortable.

Just one thing, again -- don't forget to check the hard drive for valuable data, and make sure you back anything important up off to some external medium, like an SD card or a USB memory device.

(Porn collections? Go ahead and wipe 'em. Retro computing is way more fun.)

Daily-driving User Account!

Oh, and one more thing. Just one. Promise.

PLEASE! for the love of peace, sanity, and a computer that can be somewhat protected from its internet connection, make yourself a non-admin privilege daily-driving user account to work in.

Once the default administrator-capable account is created, and everything you chose in the OS install is loaded, find where you can add users, and add a user without administrator privileges. This account should be the one you use for surfing around the internet, and for working on retro stuff, etc.

This is true no matter what OS you choose. 

I know it requires some learning of how to handle privileges and such, but it's worth it for the peace of mind and the trouble you don't end up causing others so easily.

ARM based lightweight computers

If you don't have an old computer, a Raspberry PI or similar ARM-based lightweight computer can be had for pretty cheap, and versions of Debian or Ubuntu or NetBSD (in particular) can be loaded on them. Raspberry Pi, in particular, comes with Raspberry PI OS (Raspbian) already installed by default, which is basically Debian pre-customized and pre-loaded on the PI. 

To find other computers similar to the Raspberry PI, search for "computers similar to raspberry pi" and you'll get links to lots. Le Potato, Orange, and Odroid are trending as I write this.

Note that I don't have any experience on these, but the ones named above should just work.

Mac OS

Doing this under Mac OS will also be pretty straightforward, and you don't have to worry about installing the OS. You will need to install the BSD developer tools subsystem  (cough), well, I mean, XCode, which has the compiler toolchain. But that's straightforward, too. All the libraries and bc should just come with XCode. And XCode has its own integrated editor, so you don't need to choose a text editor. (But there are lots of great 3rd party text editors available, too, including those I mentioned for Linux and BSD OSses.)

MSWindows and Cygwin

If, for some reason, you must use an MSWindows computer for this project, you probably want Cygwin.

Visual Studio will have you jumping through hoops of Microsoft telling you, "Let us help you! Let us HELP you!!!!!" and sending you on wild goose chases, mostly to get you corralled back into their world. That's not why you're reading this blog. Yes, LSW might work. If you load a Linux OS on top, it should work. But if you have questions about that, I haven't been there, and I'm afraid I won't give them priority.

So I recommend Cygwin if you can't do a Linux, BSD or Mac OS. 

Make sure you're accessing the real https://cygwin.com/ site, download the installer, and check the checksum of the installer after the download is complete.

For MSWindows 10, the command-line command for checking checksums was 

certutil -hashfile <TYPE>

search the web for how to specify the type of checksum, etc. 

Once Cygwin is installed, open up the installer again and get either the gnu C compiler or the Clang compiler. Either should work. And you'll need the ANSI and Posix libraries. While you're at it, get bc, too. (I think it's in the repositories.) I don't think they currently have gforth in the repositories, so we'll just kind of punt on that. Terminal emulation should be in the default install.

Get a text editor (see above). 

VS Code? I'm not going to tell you don't do that, but give yourself an alternative. Get a separate text editor so you can dodge when Microsoft's stuff wants to fight with you.

Checking your environment

We need to check that the compiler works. Open up a terminal emulation window (XTerm or equivalent, Cygwin shell if you are using Cygwin) and type 

cc --version

and it should report which compiler and which version. GNU's toolchain will tell you it's from the Free Software Foundation, and Clang should report that it's clang. Both should give you a version number.

If you're not getting that, check your package manager to see whether it gave you an error or something when it tried to install the compiler and toolchain.

When you get a version number, make a working directory and change into it, something like

  ~$ mkdir asmwork
  ~$ cd asmwork
  ~/asmwork$

open up an editor window or editor session and type the following program in and save it in asmwork as "beachead.c": 



/* beachead.c 
** by Joel Rees, Japan; assigned to public domain.
*/
#include <stdio.h>
#include <stdlib.h>
int main( int argct, char *args[] )
{  char * arg1 = ( argct < 2 ) ? "none" : args[ 1 ];
   printf( "%s on the beach\n", arg1 );
   return EXIT_SUCCESS;
}

 

Compiling and running it should give you something like this:

~/asmwork$ cc -o beachead beachead.c
~/asmwork$ ./beachead one
one on the beach
~/asmwork$ ./beachead
none on the beach

(Type what comes on the lines after the "$" dollar sign prompt. The computer should respond with the lines without the prompt. Don't forget ./ before the program name, so the shell knows that the beachead program is in the directory you are in.)

Compiling EXORsim

Once you have your system and  toolchain ready to work with,  open your web browser and go to Joe Allen's EXORsim repository on github:

https://github.com/jhallen/exorsim

And read through the description. For the record, we won't need to use MDOS or FLEX, and we won't need to use blank disk images. Not at this point. Maybe later. Also, whether you install EXORdisk in your system's /usr/bin to make it available to every user, or just run it from your user directories, will be up to you.

You can find a link to download the source as a .ZIP archive file by clicking the [<> code] button above the directory listing. Make a directory for EXORsim under the asmwork directory (such as "~/asmwork/exor") and unpack the archive there. Drag, select, and click in your GUI should work.

Alternatively, you can copy the URL shown there and use the git clone command -- if you've installed git. (It's worth installing, by the way.)

Change directory into the exor directory you made and then into the source code directory, if you didn't end up with the source code directly under the exor directory that you just made. Check the README file, and ...

Hold on. The build instructions you have read are okay, if you want to install it where you any user on your system can run it. If you don't want to do that, you can just make it without the sudo or runas command.

If make does not successfully complete, you'll need to look at the error messages to see if you need a library or something. But it should successfully complete on any of the OSses I've described above, if you have the ANSI and POSIX libraries installed.

If you have problems, leave a message in the comments here and I'll try to get back to you.

Now, if you don't want it installed system-wide, but you don't want to type the full (relative) path every time you run it, you can add a directory for locally runnable stuff in your user directory. Call it ~/me/prg or something you like, and add it to your search paths. Then make a symbolic link from the compiled object files into your local programs directory and you're set. 

For now, you can run these from the directory where they are compiled. Type

$ ./exor -? 

and the 6800 version of EXORsim should give you some helpful output about how to run it. For now, type "./exor --mon" and hit enter:

$ ./exor --mon
Load facts file 'facts'
'exbug.bin' loaded.
  EXBUG-1.1 detected
'mdos.dsk' opened for drive 0 (double sided)

OSLOAD...

Hit Ctrl-C for simulator command line.  Starting simulation...

>         0 A=00 B=00 X=0000 SP=00FF ------          0020: B6 E8 00 LDA E800                 

6800 Monitor: Ctrl-C to exit, 'c' to continue, or type 'help'
% 

and you are in the hosted debugger, being prompted to type a command. (The "%" is the prompt in the hosted debugger.) 

And that is enough for this post. (It has likely been a long road, really.) 

Type Q or ctrl-C to quit. Or leave it there and continue with the next post, if you aren't tired out.

Next post will be a short introduction to using EXORsim for running code on the 6800 and 6809.

 

(Title Page/Index)

 

ALPP XX-XX -- Getting Simulators for the M6800, 6801, 6809, and 68000

This chapter also got scratched. Just didn't work right. But I want to keep it around for my own reference. 

Getting Simulators for the
6800, 6801, 6809, and 68000

(Title Page/Index)

 

Okay, so we've introduced assembly language by talking a little about adding small integers. But if we want to understand what's going on, we really need some way to watch what the processor does when it executes the code.

If I had more time and money, I would design my own hardware and build my own simulator software, and offer the hardware for sale and put the software up for download and all that, and it would all be real easy to use. (Of COURSE!)

Fortunately, there are useful simulators (software-based emulators) already available, as I have mentioned.

What I will use for 6800 and 6809 code, especially in the first part of this, will be Joe. H. Allen's EXORciser simulator, EXORsim. For the 6801, it will be my hack on EXORsim, exorsim6801

For the 68000, I will be using the Atari ST (and beyond) simulator, Hatari.

I am choosing these because they seem to me to be the most generally available and accessible.

There are other options, such as XRoar for the 6809 and 6801, which simulates the Dragon, the Tandy Color Computers 1, 2, and 3, and the Radio Shack MC-10, and the original Matra Alice 4K. If Ciaran doesn't beat me to it, I may try (again) to add hosted debugging to XRoar, but you can always run a self-hosted debugger (such as Disk EDTASM) on the emulated computer. 

Now, Ciaran and his friends do provide an on-line emulator, and you can download Disk EDTASM and run it on the on-line simulator, but I don't want to be encouraging lots of people to put a heavy load on Ciaran's server. (I'll explain getting XRoar and building it locally on your own hardware later. It's a pretty steep start-up for a topic that already has a steep learning curve.)

Similarly, VCC for MSWindows requires compiling (if I read the website right), and only emulates the Color Computer 3 (6809). I think I have heard that it supports direct debugging fairly well, but cannot vouch for that. It might be an option if you're running MSWindows.

You may find you need to build Hatari, but, if you are running a Linux OS, there are probably packages for it in your OS's repository. So you aren't necessarily faced with gathering all the dependent libraries yourself and all that. 

For Mac OS, you can get it pre-built from the project website, if you haven't yet got a package manager running on your Mac. 

For MSWindows, there is a 3rd party project, that the Hatari project links to, providing Hatari pre-built -- if you really have to use MSWindows.

There are other options for the 68000, as well, but Hatari seems to be the easiest to get, and to get started working on. And it seems to have the least in the way of advanced OS capabilities to get in the way of introductory-level practice. 

(I really should figure out Musashi, but I want to get this tutorial written. That will come later. Also, Amiga under emulation is cool, but you want to know what you're doing before you dig into writing code on Amiga. Likewise classic Macintosh.)

MAME, of course, is an option. It does everything, and supports direct debugging pretty well (I hear), but it's huge, and a bit daunting to get started with.

But!   (OS and Compiling)

For any of these, you'll need something to run the simulators on, both hardware (PC/workstation) and software (support in the operating system). And you'll need compilers to build anything that needs to be built.

Compilers are definitely one thing you'll need anyway, as we go along. There are more tools we want to use, and you'll need to compile some of them.

If you can run a Linux OS, or Mac OS, or freeBSD or netBSD, getting the compiler and other tools is really straightforward. They can usually just be selected during the install process, or installed later through some sort of package manager.

If you absolutely must run MSWIndows --

Cygwin

Microsoft's compiler toolchain (VS) has one not-small problem. Pretty much anything you try to do with it will try to drag you off into Microsoft solutions, and if Microsoft solutions were sufficient, you wouldn't be reading this blog. 

If you must use MSWindows, the first tool you need to download is Cygwin. (LSW with a full Linux OS install might work, but I've never tried it. And LSW is Microsoft. I have tried Cygwin.)

Make sure you're accessing the real https://cygwin.com/ site, and check the checksum after you download it. 

For MSWindows 10, the command-line command for checking checksums was 

certutil -hashfile <TYPE>

search the web for how to specify the type of checksum, etc. 

Once Cygwin is installed, open up the installer again and get either the gnu C compiler or the Clang compiler. Either should work. And you'll need the ANSI and Posix libraries. While you're at it, get bc, too. (I think it's in the repositories.)

Also, if you don't already have a favorite text editor, get either gedit or kate, or maybe Geany. Vim or EMacs will also work, if you already know them.

At which point I'm going to repeat myself. 

Ubuntu or Debian or Devuan or Mint OS, ... 

There are lots of Linux OSses to choose from, they are mostly easy to install on older hardware you might have lying around -- or on inexpensive ARM hardware like Raspberry Pi, and they all have great compiler toolchains and other tools and repositories that are easy to install from. You can also dual boot, but, really, if you don't have a ten-year old PC in a closet somewhere that you're no longer using, a Pi or something similar is pretty inexpensive.

FreeBSD or NetBSD should work pretty well, too. OpenBSD, on the other hand, is so security oriented that I'm not sure compiling EXORsim will be very easy.

All of these have install instructions on their websites, and are easy to install. (Almost too easy. Do be careful to save any important data before wiping an old computer clean.) 

Make sure you choose a minimal developer's install, with either the gnu or clang compilers, and the basic set of libraries. And, as I mentioned for those using Cygwin, install a programmer's text editor, as well -- kate, gedit, geany, vim, emacs, or whatever.

Or if you're inclined toward Mac

Doing this under Mac OS will also be pretty straightforward, and you don't have to worry about installing the OS. You will need to install the BSD developer tools subsystem  (cough), well, I mean, XCode, which has the compiler toolchain. But that's straightforward, too. All the libraries and bc should just come with XCode. And XCode has its own integrated editor, so you don't need to choose a text editor. (But there are lots of great 3rd party text editors available, too.)

Yeah, that's a lot of stuff, just to get started, isn't it? But it's tools that you need anyway, if you are interested in assembly level programming and/or retro computing.

Once you have your system and  toolchain ready to work with, 

  1. Start with downloading and compiling EXORsim6801. 
  2. Then download and compile the most recent EXORsim. 
  3. And then install Hatari.

Well, you can install Hatari first, but please compile EXORsim6801 before compiling EXORsim, and I should explain why.

EXORsim6801




(Title Page/Index)