2nd Life


The TRS-80 model III emulator for the Atari ST, STE, TT, Falcon and compatibles



Manual for version 1.0





By Sander Berents
August 1996 and July 1997






2nd Life, 2nd Connection, 2nd Convert, Atari Connection, SPEED.BAS, RECEIVE.BAS, BIN2CMD.TOS and EXCHANGE.CMD programs copyright (C) 1995, 1996, 1997 by Sander Berents. All rights reserved. Permission to freely distribute this package in its original form is encouraged, but it must NOT BE SOLD OR ALTERED (A reasonable media charge for distribution of this package is acceptable).

TRS-80 is a registered trademark of Tandy/Radio Shack Corporation.
Starting Up

Description

This emulator package allows your Atari ST, STE, TT, Falcon or compatible to run as a TRS-80 Model III. It's able to run virtually all Model I/III applications and software. My aim was to design a convincing "virtual reality" in which a Model III program would not be able to tell that it was not running in the genuine machine. This virtual Model III includes the following options:

€Z-80 Microprocessor;
€48KB RAM, 14 KB ROM, 1 KB Video memory and 1 KB keyboard memory;
€Printer port;
€Internal Clock;
€Floppy Disk Controller and four 80-track single sided diskdrives;
The RS-232 port is not yet emulated in this version.

The emulator only runs in monochrome screen mode but in any resolution. A clock speed of at least 16 MHz is recommended.

Installing the package

After unzipping the file TRS80V10.ZIP into a folder (for example named "TRS80") you should have the subfolders "DOCS", "DISKS" and "TOOLS". Now unzip the contents of TRS80X10.ZIP in the "DISKS" folder.

See the README.TXT file for a short description of all files included in the .ZIP files.

Starting up in Model III BASIC (no DOS)

Running the emulator is very straightforward. By simply selecting "Reboot" in the menu the emulation will start. You can leave the emulation mode by pressing the UNDO key.

Virtual Drives

The virtual Model III is equipped with four 80-track disk drives. Disks are represented by *.DSK files in the emulator's DISKS path.

[the following info is not correct for v1.0 --- see README.TXT]
You can create new virtual disks in the emulator by entering an unused disk name after selecting a drive, and then running your Model III DOS's (e.g. TRSDOS, NewDOS/80, etc.) FORMAT command on it from within the emulator. The new .DSK file will automatically be created in the default directory when the Model III's FORMAT command is executed.

Leaving the disk name blank for a drive effectively leaves the drive empty. In contrast, entering an UNUSED name will cause the drive to appear to contain an unformatted disk.
[the above info is not correct for v1.0]

Note that to use the emulator as a disk-based Model III, you will have to have a DOS disk in virtual drive 0. As with the real machine if you change the contents of drive 0 (e.g. if you have more than one DOS) you should reboot the emulator.

Emulation speed

Using SPEED.BAS you can get an idea of the emulation speed. Because of the speedup patches in BASIC the Float value will approximate the real emulation speed the best. However, it "feels" much faster. My results are (in percents):

TestSTSTEFalconTT
Integer438583170
Floating Point325960121
Memory458688182
Text170311311530
Scrolling60131217333


All tests compared to a 2 MHz Model III and done using NON-DISK BASIC, 25 Hz RTC and clock adapt activated. Video acceleration and speed adapt were selected.

Menu Options

2nd Life

About 2nd Life
Here you will find the version number of the emulator you are using. This is version 1.0. Look at the end of this document to see where you can find updates.

File

Open Disk
The disk window is permanently visible in the down left corner of your screen when you have chosen for emulation of a disk system in the options window.
[manual not complete]

Close Disk
Remove the selected virtual disk from the virtual drive.

Write Protection
Disk write protection is emulated by the file system's Read Only status. To make life easier for you this status can be switched using this option.

Load Snapshot
This option let you select a *.SNP file and uses it to restore the TRS-80 memory, registers and emulator settings to the saved values.

Save Snapshot
This will save the current TRS-80 memory, registers and emulator settings into a file. It does not save the keyboard layout and font.

Quit
Quit the Emulator.

Emulate

Reboot
The program switches to emulation mode (the mouse will be invisible) and emulates pressing the reset button on the TRS-80. In emulation mode pressing Left Shift and Undo at the same time has the same effect. Press HELP in emulation mode for some extra information. You can leave emulation mode by pressing the UNDO key.

Continue
The program switches to emulation mode (the mouse will be invisible) and continues program execution.

User Defined Keyboard
The program contains two keyboard layout definitions. This option allows you to switch between the default and the user defined keyboard. The latter can be changed using the keyboard layout editor.

User Defined Font
The program contains two font definitions. This option allows you to switch between the default and the user defined font. The latter can be changed using the font editor.

Disassembler
[manual not complete]

Memory Dump
A window with the hexadecimal and ascii values of the memory bytes starting from the address pointed to by the Z-80 program counter will be displayed after selecting this menu option. Click on the arrows to move through the memory or type the hexadecimal address of the prefered address followed by clicking on the GOTO button. You can also print a part of the memory dump by entering the first and last address and clicking on the PRINT button.

Debug
After selecting the debugger the menu options for starting the emulation will be disabled. Now it is possible to execute single opcodes of the program by a mouseclick on the STEP button. By clicking the GO button you execute the program until the UNDO key is pressed or a breakpoint address has been reached.
You create this breakpoint by entering in the right corner of the window the hexadecimal address. When you enter a zero number the breakpoint will be removed.
You can change the Z-80 flags and registers, including the program counter, by clicking with the mousepointer on the registername bar. The flags and registers will change after clicking on the OK button in the appeared window.
You quit the debugger by unchecking the menu item.

Options

Emulator Options
€Disk System

If you select this option four virtual drives will be displayed on the screen in which you can put virtual disks (*.DSK files). Be sure drive 0 contains an operating system and reboot your TRS-80 after switching to another DOS. You emulate a tape based system by turning this option off. After rebooting Model III Basic will then start. After switching this option you are forced to reboot the TRS-80.
€Emulate Sound
Select this options if you want port 255 to be used for sound production. The quality is poor;
€Reverse Emulator Screen
On Model III the background is always black. Select this option for the same effect in the emulator window;
€Printer Line Feed after Return
Model III sends a return (ascii 13) after each line. This option let the emulator send a Line Feed after each return. Select it if your printer prints everything on the same line, deselect it if your printer prints an empty line after each line;
€Smart DAA Instruction
If Fast Z-80 Emulation is selected the DAA instruction is not recognized. Some programs and DOS use the DAA instruction however. After enabling this option the emulator will look at the code before and after a DAA instruction if it encounters one and will try to handle correctly. Always enable this option;
€Emulator Reboot at Startup
If 2nd Life is started and this option is enabled the emulator will reboot automaticly. Be sure to insert virtual disks in the virtual drives and saving the options if you emulate the disk system before you use this option.
€Discard Printer Output
Select this options if you don't want the emulator to send data to your printer. The TRS-80 busy line is always low if this option is selected.
€Dark Background
Select this option for a real TRS-80 feeling.
€Copy Atari Clock at Reboot
The TRS-80 does not have an internal clock with battery and will reset it when it reboots. After enabling this option the emulator will copy the current date/time used by your computer into the TRS-80 ROM so it will start with the correct time.
€Atari compatible mode
If this option is enabled the emulator will not use the low-level interrupt routines for the keyboard and joystick handling but a less powerfull high-level version which only uses TOS calls and doesn't support a joystick.
€Special BASIC tape handling
Select this option to redirect the BASIC commands CLOAD, CSAVE and SYSTEM to the Atari file system. This allows you to load disk & tape files which are stored outside virtual disks. If you turn off this option the standard rerouting will be used and you can only load/save tape-formatted files;
€Fast Video Routines
Select this option to accelerate the TRS-80 Video ROM routines more then five times. You will notice the difference only for BASIC programs and programs that use those routine (like DOS itself);
€ROM Speed Adapt
The TRS-80 ROM contains a delay routine ($60) which is used by some programs and also by the keyboard routines. If you turn on this option the emulator will make a patch to the routine so it delays correctly for your machine. Turning the option off will totally erase the delay routine. If you have problems with the keyboard handling or a game which is running to fast try this option.
€No, Slow or Normal Clock Interrupt
On a TRS-80 the clock interrupts 25 or 30 times a second (depending on the country). This option allows you to turn off the clock interrupt, set it to 5 Hz or to 25 Hz. Setting it to 5 Hz or turning it off will speed up the emulation a little.
€Adapt Clock Interrupt Routines
The TRS-80 ROM routines which handle the clock interrupt assume the clock is running at 30 Hz. Since this is never the case the emulator patches the ROM if you select this option. If you selected the 5 Hz clock the ROM routines will also be patched correctly after selecting this option. Always select this option if you turned off the disk emulation. Otherwise the clock will run to slow. If you use the disk system you probably have to turn off this option because most operating systems correct this problem.
€Illegal Instruction Warning
The emulator will warn you if a illegal Z-80 instruction is encountered. A real Z-80 doesn't care about illegal instructions so you normally should turn off this warning.
€Writing in ROM Warning
The emulator will warn you if a program tries to write in the TRS-80 ROM. You normally should turn off this warning.
€RST0 Instruction Warning
The emulator will warn you if a RST0 instruction is encountered. This instruction is used by the TRS-80 to reboot. The emulator uses it for ROM patches and only gives you a warning if the instruction is on another address. You normally should turn off this warning.
€DAA Instruction Warning
The emulator will warn you if a DAA instruction is encountered. If a TRS-80 program doesn't work correctly turn on this warning to check if it contains a DAA instruction. If so, look with the memory dump menu option at the address and write down the hexadecimal values of the bytes before and after it (minimum 10 each side) and send it to me. Using this data I can make the "smart DAA" even smarter. You normally should turn off this warning.
Keyboard Layout Editor
[manual not complete]

Font Editor
The Model III display can produce the standard ASCII text characters and 64 graphic characters. It also features 96 special characters. The last 64 of these can be switched with an alternative set of special characters (Japanese Kana characters).
This emulator allows you to change these characters (which cannot be done on the Model III). You do this by selecting the character in the font editor and changing it in the edit window. Here it is also possible to move it in it's matrix. By clicking on the appropriate buttons you can copy the character in a temporary buffer, erase it or paste the buffer. You can save and load a characterset or restore the set to it's default value.
You confirm all your changes by pressing the OK button. When you select the close button of the window you will cancel any changes.

Save Configuration
The selected emulator options, default CLOAD, CSAVE and SYSTEM filenames and virtual disk filenames will be saved. Upon starting the emulator the next time this configuration file (TRS80.INF) will be read.
2nd Connection

To take full advantage of the emulator, you're going to want to get your Model III disk software onto your Atari.

Because I don't have an RS-232 option card in my Model III I have developed a method by which the printer port of the Model III may be linked to the parallel port of your Atari for transfer.

Those without technical experience should not be scared away by this latter method. You will not be required to do anything to either computer that might void the warranties, or require any electronics experience.

All that is required is the construction of a special cable so that the two computers can be connected. This construction is very simple and may be carried out by people with no prior hardware experience.

Constructing the Cable

To start, you will need to purchase a 25-pin male D-type connector (also known as a standard PC printer connector), a 34-pin female edge-card connector (the standard counterpart to the Model III printer port), and some ribbon cable (you will need to use only 11 wires). These may be obtained at many electronics and computer stores. If a store you try does not have all the necessary parts, they may be able to direct you to another supplier.

If you look carefully, you should see that the pins on the 25-pin connector are numbered, running left to right as 1 to 13 on the top row, and 14 to 25 on the bottom row, when looking at the pin side. In contrast the front of the edge-card connector (I'll call it the 34-pin from now on) is numbered as follows:

246810121416182022242628303234
13579111315171921232527293133


This is the view from the bottom rear at the printer card-edge connector when your are sitting on the backside of the Model III.

You will need to wire the following pins together:

TRS-80Atari
NamePinNamePin
DATA 03--->DATA 02
DATA 15--->DATA 13
DATA 27--->DATA 24
DATA 39--->DATA 35
DATA 411--->DATA 46
DATA 513--->DATA 57
DATA 615--->DATA 68
DATA 717--->DATA 79
STROBE1--->BUSY11
BUSY21<---STROBE1
GROUND?<--->GROUND18 - 25

If you can, check them with a resistance meter afterward to ensure they are in good contact and connected properly.

Testing the cable

You may test the cable by connecting it to both computers and loading BASIC on your Model III. Start CONNECT.PRG on your Atari and select the Test button. After pressing the Start button it will show every byte it receives from the Model III. Now enter OUT 248,0 on the Model III. Your Atari will show the message Received 0 ($00). Repeat this using instead of 0 the numbers 1, 2, 4, 8, 16, 32, 64, 128 and 255. If one of these numbers doesn't appear in the same way on your Atari you have to check your cable and connection. Press the UNDO key on your Atari to quit this test-mode.

This cable construction has been tested and is known to be safe if properly constructed. Be careful though. I assume no liability for any damage that may result.

Transfering Files and Disks

Transfering Atari Connection

Once you have constructed and tested your cable, the rest is very simple. First type in the program RECEIVE.BAS (contained in the second .ZIP file) on your Model III. Make sure to save the program.

After loading DISK-BASIC start RECEIVE.BAS (be sure that at least 5 KB is free on the disk). Enter ATARICON/CMD:d where d is the drivenumber. The file will be created and the message Waiting for Sync Byte will appear.

Now Start CONNECT.PRG on your Atari and select the SEND button. After pressing the START button the fileselector will appear. Select ATARICON.CMD and press the OK button.

On your Model III the messages Receiving Data Blocks followed by Transmission Completed will appear. If you see messages like Checksum Error or Unknown Sync Byte or if nothing appears at all you must check your cable and the connection. Press the UNDO key on your Atari and the BREAK key on your Model III to interrupt the transmission.

From now on you will use Atari Connection (ATARICON/CMD) for sending and receiving files. This program is written in machine language and is much faster and more powerfull than the RECEIVE.BAS.

Sending Files to the Atari
Select the proper command in Atari Connection and enter the name of the desired file (possible follwed by :d where d is the drivenumber). Select the RECEIVE button in 2nd Connection and press the START button. Now enter the desired destination filename and press OK.

Sending Model III Disks to the Atari
Select the RECEIVE button in 2nd Connection and press the START button. Now enter the desired destination filename of the Virtual Disk File and press OK. Use the extension "DSK". After selecting the proper command in Atari Connection enter the desired drive number. The program will then scan the disk first to determine which sectors can be read and to prepare the correct header for the Virtual Disk File. This is followed by sending the header and the sectors to the Atari.

Sending files to the TRS-80
Select the proper command in Atari Connection and enter the destination filename (possible follwed by :d where d is the drivenumber). Be sure there is enough free diskspace. Select the SEND button in 2nd Connection and press the START button. Now select the source file and press OK.
2nd Convert

This program can convert the following files to virtual disk files which can be used by this version of the emulator:
€Model III NEWDOS/80 disk images;
€Model III TRSDOS disk images [not in the current version];
€Model I NEWDOS/80 disk images;
€Model I TRSDOS disk images [not in the current version];
€Virtual disk files belonging to an old version of the emulator (0.4 or 0.5) [not in the current version];

The first two are normally used to convert files which have been received by other programs then 2nd Connection. The next two options can be used to convert disk image files from Jeff Vavasour's PC Model I emulator and Yves Lempereur's Model I emulator for the Macintosh to model I formatted virtual disks. Put these disk after the conversion in drive 3. Using the PDRIVE command of NEWDOS I installed this drive as a single sided single density drive for you
Description of some included TRS-80 programs

Model III Basic
See BASIC.TXT in the DOCS directory.

SPEED.BAS
Using this program you can get an idea of the emulation speed. The influence of some emulator options is easy to be seen. Remember that the results are relative to a standard 2 MHz Model III using NON-DISK BASIC with a 25 Hz Real Time Clock interrupt. Since the TRS-80 ROM contains routines which are written for a 30 Hz clock its clock is running too slow. To do the same on the emulator you have to deactivate the clock adapt option for a correct comparisment.
NEWDOS can correct this problem using the SYSTEM command. I have already done this for you so you have to deactivate clock adapt. For a correct clock in NON DISK BASIC you have to activate the option.

Apparat's Disk Basic
This is a extension of Model III Basic. No silicon description available.

NEWDOS/80
See the included NEWDOS80.TXT file for the commands.

Editor/Assembler Plus
This is a macro assembler.

ACCEL3
Accel is a good BASIC compiler for the TRS-80. Accel does not compile everything but only those commands with graphic-, integer- and memory-operations. The rest is executed by the interpreter. To use Accel you have to run the JCL file from the DOS prompt. Do this by entering "DO ACCEL3/JCL". The batchfile will load disk BASIC and execute ACCEL3. Now you can load and run BASIC programs in the usual way. Compiling is done by pressing the CLEAR key and entering "/FIX". You can start the compiled program by typing the RUN command. Be sure your programs are saved before compiling since you cannot modify the source code after compiling. A compiled program can also be saved using the SAVE command. After loading the programs are executable (if ACCEL3 is in memory).

CAT
This program with an optional drive number (0-3) as argument will display the directory and allows you to start a program by selecting it using the arrow keys and the ENTER key.
Technical Information

The Z-80 and hardware emulation of 2nd Life is entirely written in 68000 assembly language. The application interface is written in C.

Virtual Disks

All current versions of the emulator only recognize single sided virtual disks with 256 bytes per sector (BPS) and a maximum of 80 tracks (version 0.4 and 0.5 of the emulator only 40 tracks). The virtual disks all consist of a header as shown below followed by all excisting 256 byte sectors in order.
Because the Data Address Mark (DAM) of the sectors is also saved the emulator can read all kind of different 256 BPS DOS formats.

Virtual Disk Header
LengthNameDescription
long wordVDSKFile type "VDSK"
long wordDSKVERVersion number
wordHLENHeader length (bytes), multiples of 512
wordBPSBytes per sector
wordSPTSectors per track
wordNTRACKSNumber of tracks
wordNSIDESNumber of sides - 1
wordRESERVED[7]Reserved
byteDAM[NTRACKS*(SPT+1)]DAM type for each sector
variablefillingZeros until 512 byte boundary

Version 0.4 and 0.5 of the emulator both use file version "0.4 ", HLEN=1024, BPS=256, SPT=18, NTRACKS=40 and NSIDES=0. Versions 0.6 and 1.0 of the emulator also uses version "0.4 " but allows to have different HLEN, SPT and NTRACKS values.
Each sector (counting from zero) has a corresponding DAM type: normal (0xfb) or deleted (0xf8). If a sector does not excists the corresponding DAM type is set to zero. The DAM array has one byte extra for each track because the counting starts with zero and the sectornumbering starts with 0 or 1 depending on the used DOS. Version 0.4, 0.5, 0.6 and 1.0 of the emulator don't have this extra byte and cannot handle disks which start their sectornumbering with 1 (like TRSDOS).

2nd Connection

If you send a data byte from the TRS-80 to the Atari the latter will behave like a printer connected to the TRS-80. All 8 DATA lines will be used, the TRS-80 STROBE line will be active (low) if the data is valid and the TRS-80 BUSY line will be high when the Atari is busy.

Sending a data byte from the Atari to the TRS-80 is more difficult because the 8 DATA lines of the TRS-80 can be used only as output. First the Atari makes the TRS-80 BUSY line low. The TRS-80 will react by sending the requested bit numbers (0 ... 7 in order) with ± 200 µ sec intervals. The Atari must react within this time interval. After these requested 8 bits the TRS-80 requests for making the TRS 80 BUSY high by sending the number 8. It is possible for the Atari to check if every bit arrived correctly because every request, except the first, from the TRS-80 contains in bit 7 the last received bit.

The communication protocol is listed in the following table.

Communication protocol
ByteDescription
3CHBlock sync
xxData length in bytes (0 means 256)
xx xx xx ...Data bytes
xxChecksum (sum of data)
(repeat block)
78HEnd of file

Updating the emulator

If you have access to the Internet you can find the latest version on the Schizoid Design home page
http://www.schizoid.demon.nl/
or on the Staggerblow home page
http://www.pi.net/~volatile/

Send an email to me if you want to be added to the 2nd Life mailinglist. I will use this list to notify you about new updates, tips and tricks. For the time being my email address is:
s.j.berents@fys.ruu.nl
If you can't reach me there, try
sanderb@and.nl
You can find my snail mail address in the program.