home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
z
/
zsim20.zip
/
ZSIM.DOC
< prev
next >
Wrap
Text File
|
1992-12-04
|
42KB
|
1,278 lines
**********************************************************************
**********************************************************************
ZZZZZZZZZZ SSSSSSSS IIII M M
ZZ SS II MM MM
ZZ SS II M M M M
ZZ SS II M M M M
ZZ --------- SS II M M M M
ZZ --------- SS II M M M
ZZ SS II M M
ZZ SS II M M
ZZZZZZZZZZZ SSSS IIII MMM MMM
The hundred percent Z80 Emulator
Version 2.0
Copyright (C) 1990, 1992 by Jürgen Weber
Jürgen Weber
Wiesentalstr. 1
W-7170 Schwäbisch Hall
Federal Republic of Germany
email: weberj@dia.informatik.uni-stuttgart.de
**********************************************************************
**********************************************************************
IMPORTANT:
The author assumes no responsibility for the correctness of the
documentation or the function of the program. The user is advised to
test the program fully. The risk of using the software is exclusively
at the user. The author assumes no responsibility whatever for damages
of any kind that might result from using the program.
Cited product names are trade names.
Minimal Hardware/Softwarepreconditions:
AT 286, 1 Diskdrive (5 1/4 inch recommended), 256K free memory,
MsDos 2.1 or compatible.
Serious work is only possible with machines faster than 8 MHz 80286.
Every 10 MHz shown by the Landmark test correspond to 1 MHz of the
emulated Z80.
IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT
*********************************************************************
IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT
Be sure that you do not insert a MS-Dos disc when prompted for a CP/M
disc. The CP/M bios would overwrite the MS-Dos disc without prompting.
Also MS-Dos overwrites CP/M discs.
As soon as the emulator prompts for inserting a CP/M disc only use
CP/M discs.
Be sure that the CP/M disc has the right format. Insert the disc
WRITE PROTECTED and enter DIR to display the directory. If only dots are
displayed it is a clue for a wrong format. But also if "NO FILE" is
displayed it might be a wrong format except if you are sure that the
disc is indeed empty.
CONTENTS:
I GENERAL
II EMULATOR
III DISK FORMATS
IV SCREEN DRIVER
V PRINTER
VI ENDING THE EMULATION
VII CONTROL BREAK MENÜ
VIII DISC PARAMETERS
IX EMULATION OF THE Z80
X BENCHMARKS
Appendix 1: Screen control sequences
Appendix 2: Description of the bios functions
Appendix 3: undocumented Z80 Op-Codes
Appendix 4: A test for the emulation
Appendix 5: How to use interrupts
Appendix 6: The DOSFTP utility
Appendix 7: An example for IOBYTE usage
INSTALLATION:
=============
Copy the files in the package into a directory of your harddisk.
I GENERAL:
===========
ZSIM emulates a Z80 CP/M Machine (CP/M 2.2), but not the CP/M
operating system itself. In order to start CP/M, a CP/M System disc
must be inserted into drive A:, where from ZSIM boots CP/M. The
CP/M system or a compatible operating system (SUPERDOS and Z80DOS are
included in the ZSIM package) also can be put into a file CPMSYS.CPM
on the hard disk.
Every CP/M program I could test ran correctly, even the floating point
library of the public domain program SMALL-C, that requires a high
compatibility, as it uses undocumented Z80 codes.
The complete compatibility to a CP/M machine is reached because
contrary to other emulators that emulate the operating system itself
ZSIM only emulates the Z80 and the bios. On this virtual machine runs
the original CP/M or a CP/M compatible operating system.
II) EMULATOR:
=============
In the following only the specialties of the virtual CP/M machine are
described. For information concerning the CP/M operating system please
consult literature covering this subject, for example D.E.Cortesi:
INSIDE CP/M.
ZSIM creates a CP/M machine with 64K ram, one disk drive and a
ramdisc. There is only one physical drive supported. The physical
drive can be set to IBM-PC drive 0 or 1 by changing the disc parameters
in the control-Break menue. The physical drive is always CP/M drive A.
The whole memory pool that is not required by Dos, ZSIM and the 64K
working space for the Z80, is used as ramdisc (440K ramdisc in a 640K
PC). You can restrain the size of the ramdisc using parameter /snnn.
For example /s300 means use a maximum of 300 kilobytes for the
ramdisc.
The ramdisc can be saved in a MS-Dos File, that will be
automatically loaded starting ZSIM next time, but only if there is
enough memory for the ramdisc. So don't use more TSRs next time. Or
always use parameter /S.
You can keep important utilities in the ramdisc and have them
present every time you start ZSIM.
STARTING:
While starting ZSIM tries to load CP/M Bdos from a MS-Dos file
CPMSYS.CPM into memory. The file must be in the directory ZSIM was
started in.
The ZSIM package contains two CP/M compatible operating systems in the
files SUPERDOS.SYS and Z80DOS.SYS. Both contain the ZCPR1 command line
processor. Z80DOS is a derivative of SUPERDOS and supports date and
time (ZSIM's bios furnishes time and date). But there may be write
errors if you use discs that were already written to by the original
CP/M system. This is because Z80DOS uses a slightly different, faster
file system.
Note: There seems to be a bug within SUPERDOS as SMALL-C vers. 2.1 will
not work with it. SMALL-C vers. 2.1 does work with the original CP/M
and with Z80DOS. Until now SMALL-C 2.1 is the only program I found
that does not work with SUPERDOS.
To use one of the public domain operating systems simply copy
SUPERDOS.SYS or Z80DOS.sys to CPMSYS.CPM:
COPY SUPERDOS.SYS CPMSYS.CPM
If you format a disc using the utility CPMFRM you can start CP/M
programs, e.g. Small-C, without having the original CP/M operating
system. Create as described above CPMSYS.CPM, insert a disc formatted
by CPMFRM and start ZSIM.
If CPMSYS.CPM is not present, ZSIM tries to load the system from the
boot tracks by scanning all sectors within the reserved tracks for the
Copyright message of Digital Research. If it is found DR's copyright
is displayed and the following sectors are loaded as system. A system
disc is only required for boot up, afterwards the system is kept in
memory.
Even if you would like to use the original CP/M a system disc is only
necessary to start ZSIM. Afterwards the system is kept in memory.
After successful boot from disc you can create with MOVCPM a file
containing an image of the system (don't forget the blank between
the * *) and transfer it to MsDos.
Example:
jgw 64K cp/m 80 bios ver 2.0 -- 11/18/92 (C) 1990,1992 by Jürgen G. Weber
BDOS: COPYRIGHT (C) 1979, DIGITAL RESEARCH
B>a:movcpm * *
CONSTRUCTING 64k CP/M vers 2.2
READY FOR "SYSGEN" OR
"SAVE 34 CPM64.COM"
B>save 34 cpmsys.cpm
B>dosftp
Enter help for a command list.
WARNING: DO NOT ACCESS your physical CP/M drive (MSDOS drive B:)
with the exec command.
dosftp> put cpmsys.cpm
dosftp> quit
Bye.
B>
You can specify behind MOVCPM a smaller number, too. This generates a
smaller CP/M system and leaves Z80 memory behind CP/M TPA and the
system area. ZSIM automatically loads the smaller CP/M to the right
place.
The public domain operating systems SUPERDOS and Z80DOS are always
loaded by ZSIM in a way that bdos is situated at 0ec00h.
III DISK FORMATS:
=================
Following CP/M disk formats are supported:
Amstrad CPC System (169K, phys. Sektors 41h-49h)
Amstrad CPC Data (178K, phys. Sektors 0c1h-0c9h)
CP/M 86 SS DD (153K)
CP/M 86 DS DD (316K)
and additionally a special format corresponding to CPC data format
but with physical sector numbers starting at 1.
The Amstrad is a Z80 Homecomputer that was quite popular in Europe in
the middle of the eighties.
The first two formats are special formats of the Amstrad CPC. The high
nibble of the sector number is used to differentiate the formats. The
other two are used by CP/M 86 on an IBM PC and also by CCP/M 86 and
DOS Plus, that was shipped with the Amstrad PCs. Dos Plus is compatible
to CP/M 86 and PC-Dos and good for copying between CP/M and MsDos.
An additional advantage of this format is, that discs can be created
using Dos FORMAT.COM (FORMAT /8). But before that the sector fill byte
in the drive parameter table of Dos must be set to 0e5h. If you find
this to be too awkward you can use the program CPMFRM.EXE. It installs
the necessary parameters and calls FORMAT.COM. If there is the Msdos
default fill byte 0f6h in the CP/M directory CP/M sees an entry and
thinks the disk is full.
ZSIM recognizes the format of the inserted disk at every warm boot if
it is one of the five specified above. So every time you insert
another disk you should press Control-C. But this is recommended
anyway as Bdos aborts with "Bdos Error on A:RO" on any write attempt
to a disk that was not logged in with Control-C.
It is possible to manually edit the disc parameters from the Control
Break Menu and adapt them to a given manufacturer dependent format.
Also you can start ZSIM with parameter /f <diskparfile>.
<diskparfile> can be created by Control-Break menu Save Parameters.
Note that single density formats are not supported by the IBM Bios and
8 Inch disks don't like being pressed into a 5 1/4 Inch drive.
IV SCREEN DRIVER
================
The screen driver supports the CP/M Plus screen control codes.
Additionally a subset of control codes of the Amstrad CPC is
supported. For a description of the control codes see appendix 1.
Contrary to Digital Research's recommendation Bit 7 of the input ascii
code is not zeroed.
If you enter an international character (e.g. a German umlaut) it is
translated from IBM coding into CP/M coding (e.g. ä => { ). To display
an international character set it should be switched on by ESC 2 2.
V PRINTER:
==========
Characters are sent to printer lpt0. ZSIM waits until the printer has
taken the character correctly. This can result in an infinite loop if
the printer is switched off. To prevent this there is a test for
Control-C. If it is pressed there is a warm boot. This is only
recommended in case of emergency because this way the calling program
is aborted too, of course.
PUNCHER:
========
Digital Research specified function 6 for serving a puncher.
As punchers haven't great importance anymore I used functions 6 and 7
to transfer data to MsDos and vice versa. Characters are appended to
the MSdos file PUNCH.CPM. It is created if non existent. Characters
are buffered until buffer full. The buffer is also written out if you
hit Control-Break.
NOTE: Since ZSIM version 2.0 there is a utility called dosftp
for filetransfer between CP/M and dos.
See appendix 6
Calling function 6:
It's easiest done with PIP. But don't use the logical device PUN:
(Puncher) because then PIP first sends some zero bytes. You should
either use PTP: or UP2:. If you use PTP: and transferred an ascii file
PIP appends EOF.
PIP UP2:=ANYFILE.EXT[o]
The option [o] (object file) prevents PIP's stopping after the first
1ah (EOF) byte while transfering a non ascii file. The option is not
necessary for transfering an ascii file.
Remind that data are APPENDED to PUNCH.CPM.
You should precede as following:
- transfer the file with PIP as described above
- in Control-Break menue select OS Shell and under MSDOS
renam PUNCH.CPM into the name you want:
REN PUNCH.CPM file.txt
EXIT
VI ENDING THE EMULATION:
========================
The Z80 emulation can be terminated by pressing Control-Break where
after a menue pops up. You will also see this menue if the emulator
encounters the Z80 code HALT.
In rare cases a fatal error can occur: Dos loads ZSIM and its disc
buffers to an unlucky address, that a so called DMA Boundary Crossing
is happening. Then the emulation is instantly aborted. The emulator
must be loaded to another address. Simply start a new shell by
entering COMMAND and afterwards ZSIM again.
VII CONTROL BREAK MENUE
=======================
After pressing Control Break the following menue pops up:
┌─────────────────┐
│Continue │
│Save Ramdisc/Quit│
│Quit │
│Save Ramdisc │
│Delete Punch File│
│Init Reader │
│OS Shell │
│Disk Parameters │
│Save Parameters │
│Load Parameters │
│Swap Drives │
│Reset Screen │
│Warm Boot │
│About │
└─────────────────┘
Use the cursor keys to select the action you wish. Esc finishes the
menue, same as Continue.
Continue continues the CP/M emulation
Save Ramdisc/Quit saves the ramdisc to the disc ZSIM was started
from and ends ZSIM.
Quit ends ZSIM without saving the ramdisc.
Save Ramdisk saves the ramdisc and continues the emulation.
This makes sense if you wish to save different
contents of the ramdisc. Important: after that
you have to start an OS Shell and rename the
saved ramdisc (RAMDISC.CPM) else it would be
overwritten if you save the ramdisc next time.
Delete Punch File deletes the MsDos file, the punch data are written
into.
OS Shell starts an Dos Shell, but you only get 128K memory
for it. But that is enough for REN and COPY. ZSIM
first looks in the environment variable COMSPEC for
the location of COMMAND.COM. If COMSPEC is not set
ZSIM tries to start \COMMAND.COM on the drive ZSIM
was started.
Disk Parameters is used for editing the CP/M disc parameters
(described below).
Save Parameters saves the disc parameters to a file. Enter
for that a filename with extention. The parameters
are saved as hexbytes in the same order they appear
in the edit box. Before the parameters the bytes
'JW' are saved as signature.
The autologin flag and physical drive are not saved.
Load Parameters loads the disc parameters from a file that was
saved with Save Parameters. Enter for loading the
filename with extention. After loading the
autologin flag is cleared and a warm boot is made.
Swap Drives Drive A: becomes B: and vice versa
This is useful if you want submit to write its
temporary data onto the ramdisc.
If you additionally set the autologinflag to 0
you can work really fast on the ramdisc.
Reset Screen has the same effect as output of the control
sequence ESC @
Warm Boot has the same effect as pressing Control-C under
CP/M, but it also works if a program runs.
After warm boot via this option drive A: is
selected. It is possible that a Z80 program hangs
with an illegal drive selected. It would keep the
illegal drive forever if you couldn't reset it to
A:
Also the IOBYTE is reset.
About tells the program name and Author.
VIII DISC PARAMETERS
====================
If you select Disk Parameters in the Control-Break menue you can edit
the parameters in an edit panel.
During input only valid hex digits are accepted, other characters are
ignored. ESC ends editing, changes until the line before the cursor
are valid. Use BACKSPACE to delete characters in the cursor line. An
input line must be ended with ENTER. If you press ENTER without having
entered a new value the old value is kept (like in the following
example in the lines where there is no value behind the colon).
Example:
jgw 59K TPA cp/m 80 bios ver 1.1 -- 10/12/91 (C) 1990 by Jürgen G. Weber
BDOS: COPYRIGHT (C) 1979, DIGITAL RESEARCH
Unknown disc format. Insert new disc and press any key
┌──────────────────┐
│SPT: 0024 : 28 │
│BSH: 03 : │
│BLM: 07 : │
│EXM: 00 : │
│DSM: 00A8 : B8 │
│DRM: 003F : │
│AL0: C0 : │
│AL1: 00 : │
│CKS: 0010 : 40 │
│OFF :0002 : 3 │
│ │
│DRV: 00 : │
│PTR: 28 : │
│PST: 09 : 5 │
│BPS: 02 : 3 │
│FSC: 01 : │
│LOG: FF : 0 │
└──────────────────┘
Here I had inserted an alien disc (Osborn DD). After ZSIM had
complained about an unknown disc format I had pressed Control-Break.
Afterwards I entered the correct values.
The parameters in the upper half are standard CP/M parameters.
How to get these parameters ?
You can get those parameters either from other sources. The shareware
program 22DISC from Sydex contains a large list of disc formats.
If you have to explore them yourself, you must run your CP/M computer.
One way to get the parameters is with STAT.
I have written behind the output of STAT the name of the value in the
disc parameter menue.
B>stat a:dsk:
A: Drive Characteristics
1224: 128 Byte Record Capacity (-> record size = 128 Bytes)
153: Kilobyte Drive Capacity (DSM+1)
64: 32 Byte Directory Entries (DRM)
64: Checked Directory Entries (CKS)
128: Records/ Extent
8: Records/ Block (-> Blocksize = 128*8 )
32: Sectors/ Track (SPT)
1: Reserved Tracks (OFF)
Now the entries BSH, BLM, EXM, AL0 and AL1 are still missing.
BSH (block shift) is log2(Blocksize/128)
BLM (block mask) is Blocksize/128-1
EXM (extent mask) is (Blocksize/1024)-1
AL0, AL1 is a 16 bit vector, that describes where the directory blocks
are. If we have 64 directory entries (as above) we need 64*32 bytes
= 2048 bytes, so we need 2 blocks for the directory and got
AL00 = 11000000b
AL10 = 00000000b
AN EASIER WAY
=============
Now that we have learned to calculate the disc parameters I show a way
to simply copy them. Run on your old CP/M machine DDT (do not enter
the ; and the rest of the line).
A>b:ddt
DDT VERS 2.2
-l0
0000 JMP FA03 ; to get the bios entry addresses
0003 NOP ; the high byte is FA
; (this may be at another place in your machine)
-a100 ; now enter some 8080 code:
0100 mvi c,0 ; take drive 0
0102 call 0fa1b ; take the high byte from above + 1B
0105
-g100,105 ; execute it
*0105
-x
C0Z0M0E0I0 A=00 B=0000 D=0000 H=FEB0 S=0100 P=0105 LXI B,4F43
; the address of the bios parameter block is in HL (here FEB0).
-dfeb0
FEB0 00 00 11 00 00 00 00 00 EE FE D0 FE 6E FF 7E FF ............n.~.
^^ ^^
...
; We only need the entries at offset 0A + 0B. This is the address of
; the disc parameter block we need.
; and here we got them!
-dfed0
FED0 20 00 03 07 00 98 00 3F 00 C0 00 10 00 01 00 20 ......?.......
SPT BSH EXM DRM AL1 off
BLM DSM AL0 CKS ^ the end
Note that there is no way to get the parameters PTR to FSC. You have
to look into the manual of your CP/M computer, get them from some
other source (e.g. 22DISC, see below) or try them out.
Now we copy those values into the disc parameter menue and get:
┌──────────────────┐
│SPT: 0020 : │
│BSH: 03 │
│BLM: 07 │
│EXM: 00 │
│DSM: 0098 │
│DRM: 003F │
│AL0: C0 │
│AL1: 00 │
│CKS: 0010 │
│OFF :0001 │
│ │
│DRV: 01 │
│PTR: 28 │
│PST: 08 │
│BPS: 02 │
│FSC: 01 │
│LOG: FF │
└──────────────────┘
The parameters DRV to LOG are an extention by me and mean the
following:
DRV: physical number of the drive with the CP/M disc (0 or 1);
but this is always drive A: withing CP/M
PTR: physical track number, 40 with a 360K drive, else (with 720K,
1.2 MB or 1.4 MB) up to 80 tracks
PST: number of physical sectors per track, 9 with 360K drives
BPS: physical sector length; BPS=log2(SecLen in bytes )-7; this value
is required by the disc controller
FSC: physical number of first sector of a track, usually 1
LOG: FF=autologin, 0=no autologin
If you change the parameters you should set LOG to 0, else the next
autologin would change the parameters again.
To get standard parameters, set LOG to FF, insert a disc with normal
format and press Control-C. But a secure format adaptation only is
possible with single sided formats. Some double sided formats address the
second side as extention of the tracks of the first side (with the
effect of more sectors per track), others double the track count.
ZSIMs bios uses the method of CP/M 86 double sided (double sector
count and track translation).
IX EMULATION OF THE Z80
=======================
The emulated machine behaves almost completely like a Z80 CP/M
machine.
All emulated Z80 instructions that change or use flags where tested
(especially how they influence flags). All defined flags are
influenced exactly as on an original Z80 chip. I tested this by
looping the register pair HL from 0 to FFFFh and copying it with PUSH
HL - POP AF to AF, executing the instruction to test and adding the
resulting AF register pair to a check sum. I improved the emulation
until all flag influencing instructions resulted the same checksum on
the Z80 and on the emulation. The Z80 test program is in appendix 4.
The Z80 flags that are not defined by Zilog and show more or less
random behaviour are not defined within ZSIM either. But different not
defined flag stati may result.
ZSIM supports non documented Z80 instructions, so called illegal
opcodes (see Appendix 3 for a description).
All CP/M programs I tested run with ZSIM as on a CP/M machine, even
the floating point package of the small-C compiler that uses
undocumented Z80 instructions.
A preeminent difference between emulation and original Z80 chip is
the execution time. There is no proportional relation between the takt
cycles an operation takes on the emulation and the cycles needed on a
Z80. So you cannot realize time critical applications like cassette
storing routines with ZSIM.
A Z80 uses the R register for refreshing dynamic rams and continually
increments it. Some programmers used this on a Z80 as random
generator. So ZSIM loads it with "random" values derived from the
system time.
Port operations do not execute port accesses, as input you get 0FFh.
The flags are set and port operations with block repeat change the
count registers accordingly. You can change the action of port commands
in module PORTIO.
X BENCHMARKS
============
Some Tests of the speed of the emulation (version 1.2):
I used the following benchmarks:
1) Compile the program TEST.C included with Ron Cains Small C
Compiler.
The executable TEST.COM is very hard to emulate as its floating
point routines use undocumented Z80 ops. Contrary to all other
emulators I know, ZSIM emulates these operations correctly and
TEST.COM works.
2) Compiling MC.PAS (on the Turbo disc) with TURBO PASCAL 3.0 on
disc.
3) Compiling LISTER.PAS (on the Turbo disc) with TURBO PASCAL 3.0 in
memory.
4) Enter a short assembler loop with the debugger and execute it:
LD B,20
L1:LD HL,0
L2:INC HL
LD A,H
OR L
JP NZ,L2
DJNZ L1
5) let DDT dump a range of memory:
D0,8000
RESULTS (on a 16 MHz 386 SX), Z80 Tests were run on an Amstrad CPC,
Z80 A, 4 MHz:
TestNr ZSIM:Z80 CPC/Z80 ZSIM
1 0,85 3.37.00 3.04.00
2 0,88 1.20.00 1.10.00
3 0,99 0.03.65 0.03.63
4 1,37 0.17.10 0.23.45
5 0,41 4.06.00 1.40.00
Nr. 4 is the test that says most about emulation speed because here
only calculation time without bios overhead is measured.
Test Nr. 1 strains the disc drive as compiling, assembling and linking
are made on disc. The huge disk buffers of ZSIM greatly speed this up.
Test Nr. 4 is similar to test 1.
Test Nr 3 should give a similar result as Nr. 4, but Turbo Pascal
continually displays the line it compiles therefore the slow screen
output of the CPC takes time.
In test Nr 5 screen output is the bottle neck, where the CPC with its
text output in graphic mode has no chance against the screen output of
an 80386.
Appendix 1: Screen control sequences
====================================
Implemented screen control sequences:
CPC
Ascii Operation
2 cursor off
3 cursor on
7 Bell
8 Cursor left
9 Cursor right
10 Cursor down
11 Cursor up
12 clear screen
13 Cursor to beginning of line
16 delete char under cursor
17 delete line to cursor
18 delete line from cursor
19 delete screen to cursor
20 delete screen from cursor
24 toggle highlight
30 cursor home
31 x y cursor column x,line y (home = 1,1 )
CP/M Plus:
ESC @ Init Screen: CLS,HOME,highlight off, cursor on,
underline off, US char set
ESC 2 x select country character set:
x country:
0 USA
1 France
2 Germany
3 Britain
4 Denmark
5 Sweden
6 Italy
7 Spain
ESC A cursor up
ESC B cursor down
ESC C cursor right
ESC D cursor left
ESC E clear screen, cursor keeps position
ESC H cursor home
ESC I cursor up, scroll if necessary
ESC J clear screen from cursor
ESC K delete line from cursor
ESC L insert line
ESC M delete line
ESC N delete char below cursor
ESC Y y x cursor to column x,line y, Home = 32,32
ESC d delete line to cursor
ESC e cursor on
ESC f cursor off
ESC j store cursor position
ESC k get stored cursor position
ESC o delete line to cursor
ESC p highlight on
ESC q highlight off
ESC r underline on
ESC s blinking on
ESC t blinking off
ESC u underline off
Appendix 2: Description of the bios functions
=============================================
Technical description of the implemented CP/M 80 Bios
Every Bios routine is called by executing an pseudo
Z80 CALLN opcode (EDED) with biosnumber as following byte.
Description of the calls:
0 Cold boot
Loads Bdos from MS-Dos file CPMSYS.CPM into memory and installs bios
jp table and disk parameters in Z80 ram. Drive A: is selected,
IO-Byte is set to 81h, buffer is cleared and control passed
to bios routine warm boot.
If CPMSYS.CPM does not exist, boot tries to load Bdos from the
system tracks. ZSIM searches all reserved tracks (<OFF) for the
copyright message of Digital Research. If found the following
sectors are loaded as Bdos.
If this was successful you can create with MOVCPM a file that
contains the Bdos. This file must be transferred to the MS-Dos Start
Disk of ZSIM and be renamed to CPMSYS.CPM.
1 Warm boot
Copy the bdos that was loaded by function 0 into memory to its
correct position in the Z80 memory area. ZSIM takes the correct
address specified by MOVCPM. Afterwards it is tested if the disc has
a known format. If known the right disc parameters are created. Now
the Z80 simulator is started and CP/M CCP called.
2 Consol Status
return offh in A if there is a char ready on keyboard.
Functions 3 to 7 have behaviour corresponding to the value of
the iobyte.
3 Consol Input CON:
return ascii code from CON: in A.
assignable devices set to
TTY: crtin
CRT: crtin (default)
BAT: reader
UC1: crtin
crtin:
Contrary to suggested by Digital Research Bit 7 is not cleared.
If an international character (e.g. German Umlaut) is input it is
transformed from IBM code into CP/M code (e.g. ä => { ).
International character sets are only displayed if switched on with
ESC 2 x.
Extended PC keys: If in CONIO.ASM the constant WS_KEY is set to
TRUE, the cursor keys, Ins, Del, Home, End, PgUp and PgDn are
converted to wordstar control sequences (^Q... ). The following call
of conin returns ^Q and the next the corresponding Code.
4 Consol Output CON:
assignable devices set to
TTY: crtout
CRT: crtout (default)
BAT: punch
UC1: crtout
crtout:
Displays char in C on screen. Control sequences are evaluated as
described in appendix 1.
5 List Character LPT:
assignable devices set to
TTY: punch
CRT: crtout
LPT: lpt0list (default)
UL1: lpt1list
lptXlist:
Copies char in C to printer lpt X. Waits until the printer has
accepted the char correctly. This would result in an infinite loop
is there is no printer. Therefore the function tests for Control-C.
If pressed, a jump to Z80 address 0 follows. There is normally a
jump to warm boot.
6 Punch Character PUN:
assignable devices set to
TTY: filepunch (default)
PTP: filepunch
UP1: com0list
UP2: com1list
comXlist: put character to comX
This functions should be programmed better
as I only implemented stub functions.
filepunch:
Digital Research provided this function for serving a puncher.
As punchers/readers aren't of overwhelming importance anymore I used
this function to transfer data to MS-Dos. Characters transferred to
this function are appended to the MS-Dos file PUNCH.CPM. If it does
not exist it is created.
The characters are buffered and written out, if buffer is full. This
buffer is written out too if the Control-Break menue pops up.
7 Read Character RDR:
assignable devices set to
TTY: filereader (default)
PTR: filereader
UR1: com0read
UR2: com1read
comXread: get character from comX
This functions should be programmed better
as I only implemented stub functions.
filereader:
Reads characters from MS-Dos file READER.CPM. This only works with
files that don't contain CPM_EOF (26). The PIP option [o] does not
help as there is no way to signal PIP the actual end of file and PIP
gets stuck in an infinite loop.
If READER.CPM does not exist or is read to end, CPM_EOF (26) is
returned.
To differentiate EOF from a 26 byte in a binary file this function
additionally returns at the end of READER.CPM -1 (0ffffh) in HL else
H=0, L=char. This is not provided by DR and is not interpreted by
standard programs especially not by PIP!
The following assembler lines return the character read in L or -1
in HL:
LD HL,(1)
LD DE,6*3 ; BIOS READER, RETURN IN HL OR -1 IF ERROR
ADD HL,DE
JP (HL) ;
After transfering a file you should execute Init Reader in Control
Break menue.
Example:
PIP B:ANYFILE.TXT=RDR:
8 Home
Should return the read/write heads of the drive to track 0, but is
not executed for speed reasons. Only set track with parameter 0 is
called.
9 Select Disk
Selects the Drive given over in register C and returns if the drive
exists in register HL a pointer of its DPH else 0. There are only
the physical drive A: and the ramdisc b:
10 Set Track
In register C.
11 Set Sektor
In register C.
12 Set DMA
Register BC contains Data transfer buffer.
13 Read Sector
Reads the sector selected by functions 9,10,10. Reading from
ramdisc is quite easy. Reading from disk is more difficult as for
reasons of speed the directory track and one data track are
buffered in ram. First must be decided if the sector is already in
buffer. If not the track first must be read from disk. Afterwards
the correct address in buffer must be calculated.
14 Write Sector
Writes the sector selected by functions 9,10,10. Writing to
ramdisc is quite easy. Writing to disk is more difficult as for
reasons of speed the directory track and one data track are
buffered in ram. If the sector is in the directory track the sector
is written out immediately for security reasons. Otherwise the
sector is buffered in ram. It is save enough only to write out the
directory track immediately as after changing a file the directory
is updated which results in writing out the directory track and the
data track.
15 ListStatus
Signals if the printer is ready to receive (A=1 = ready).
16 Sector Translation
Some CP/M systems make a logical sector translation for the skew
factor. This is done by function 16.
26 read/set time and date
This function is a supplement not provided in the CP/M 80 Bios. It
works like in CP/M Plus. It is also supported by the Public Domain
Bdos Z80DOS. To use it in the source of Z80DOS the entry address of
time must be set:
BIOStim equ BIOS+4EH
Writing of date and time (c=0ffh) is not supported in order not to
change the real time clock of the PC.
A call with C=0 reads the time and returns a pointer in HL to the
following structure:
dw @date ; full days since Jan, 1st, 1978
db @hour ; hours in BCD format
db @min ; minutes in BCD format
db @sec ; seconds in BCD format
30 user
CP/M 3.0 reserves function 30 for user subroutines. The ZSIM bios
offers some subfunctions of function 30 to copy data to and from
msdos. As this is incompatible to all other bios implementations it
is not described here. Look at the bios sources if you are
interested.
Appendix 3: undocumented Z80 Op-Codes
=====================================
Description of undocumented Z80 Op-Codes (as far as I know them)
The IX,IY registers can be used as 8 bit registers XL,XH,YL,YH
analogous to H and L. They are coded as the corresponding H/L
operations with 0ddh/0fdh prefix for IX/IY.
e.g.: 8D ADC A,L -> FD 8D ADC A,LY
This works with all 8080 (that means no Z80 commands with CB or ED
prefix) commands that use the 8 bit register H or L with the
restriction, that only one register of the set { H,L,HX,LX,HY,LY } may
appear in the command. E.g. LD L,LX does not work.
TSTI (C) (Code ED 70) sets the flags corresponding to the value of
port (C).
SLIA s (shift left inverted arithmetic) works like SLA but
bit 0 := 1
It is coded as CB 00110rrr (rrr coded as in SLA).
The following are NOT implemented in ZSIM, as they are too
eccentric.
DD CB ofs XX with XX=10bbbrrr,11bbbrrr (rrr=110 for (HL) is the
documented BIT|SET b,(IX+d) ) works as
CB ofs XX ( RES|SET (IX+d)) but afterwards rrr:=(IY+d). )
XX=01bbbrrr for BIT works as the documented version.
DD CB ofs XX with XX=00cccrrr works as CB ofs XX with a CMD of
{RLCA,...,SRL, and SLIA}, but afterwards rrr:=(IX+d).
With rrr=110 you get the documented CMD (IX+d)
e.g. DD CB ofs 00101110 = SRA (IX+offs).
Appendix 4: A test for the emulation
====================================
I ran the following code on the emulation and on a Z80 chip.
Both bring the same results.
TSTZ80.MAC:
.z80
; DE' := CHECKSUM OVER F
; HL' := CHECKSUM OVER A
JP MAIN
TSTZ80:
REPT 16
NOP ; INSERT CODE HERE
ENDM
RET
MAIN:
LD HL,0
LD DE,0
EXX
LD BC,0 ; LOOP OVER 0FFFF COMBINATIONS OF A AND F
L1: PUSH BC
LD A,C
AND 11010111B ; USE ONLY DOCUMENTED FLAG BITS
REPT 6*2
NOP ; SET/MASK FLAGS HERE IF NECESSARY
ENDM
LD C,A
PUSH BC
POP AF ; A:=B; F:=C
LD H,B
LD L,C
CALL TSTZ80
CALL CHECK
POP BC
INC BC
LD A,B
OR C
JP NZ,L1
RST 30H ; ZSID END
CHECK:
; BUILDS SIMPLE CHECKSUM OVER A AND F
EXX
PUSH AF
LD B,A
LD C,A
LD A,H
XOR B
LD H,A
LD A,L
XOR C
LD L,A
ADD HL,HL
POP BC
LD A,C
AND 11010111B ; MASK UNUSED FLAG BITS
LD C,A
LD B,A ; B=C=F
EX DE,HL
LD A,H
XOR B
LD H,A
LD A,L
XOR C
LD L,A
ADD HL,HL
EX DE,HL
EXX
RET
END
END OF TSTZ80.MAC
Appendix 5: How to use interrupts
=================================
The following code was entered with a debugger and displayed as result
the @. Note that in the source of the cpmbios the interrupt option
must be enabled to enable interrupts. By default the interrupt option
is disabled.
The following code does not work with the 8080 version of the
emulation. The comments behind ; may not be entered within the
debugger.
#a100
0100 im 1 ; do a RST 38H at interrupts
0102 ei ; enable interrupts
0103 jp 103 ; do an infinite loop in order not to enter bios
0106 . ; as interrupts will not occur within bios
#a38 ; the interrupt service routine starts at 38h
0038 ex af,af' ; cp/m offers not enough stack space to save
0039 exx ; registers, so swap to the alternate register set
003A ld c,40 ; '@'
003C call 0f90c ; address of console output within ZSIM
003F exx ; (don't use BDOS, it's not reentrant)
0040 ex af,af' ; and restore registers
0041 ei ; an interrupt acknowledge disables interrupts
0042 ret
0043 .
#g100 ; start program at 100h (it goes into a loop)
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@
Appendix 6: The DOSFTP utility
Since ZSIM version 1.4 there is a utility called dosftp
for filetransfer between CP/M and dos.
It makes use of bios function 30 to transfer data to dos.
Simply enter dosftp to start it. Dosftp prompts with dosftp>
You cannot abbreviate the commands.
B>dosftp
Enter help for a command list.
WARNING: DO NOT ACCESS your physical CP/M drive (MSDOS drive B:)
with the exec command.
dosftp> help
help
dir ldir mput mget
get put prompt exec
lera quit
dosftp>
In the fellowing wildarg stands for an argument with wildcards,
eg. *.C
dir wildarg displays the files of the current dos directory
ldir wildarg displays the files of the current cp/m disc
mput wildarg copies files from cp/m to dos
mget wildarg copies files from dos to cp/m
put arg copies one file from cp/m to dos, you may specify a
dos name: put cpm.c dos.c
get arg analogous to put
prompt toggles a flag. If flag is set you are prompted before
each multiple action (mput,mget,lera)
exec arg executes dos command arg
eg: exec xcopy dos.c dos1.c
lera wildarg deletes cp/m files
quit or press ctrl-c
Appendix 7: An example for IOBYTE usage
Display the old assignment from logical devices to physical devices:
A>stat dev:
CON: is CRT:
RDR: is TTY:
PUN: is TTY:
LST: is LPT:
Assign CON: to bat, that is read from RDR: and write to PUN:
ZSIM default for RDR: is read from msdos file READER.CPM and for
PUN: write to msdos file PUNCH.CPM
READER.CPM should contain some commands, e.g. DIR
and at the end: stat CON:=CRT: to reset it to keyboard/screen.
for example:
stat DSK:
stat con:=crt:
Now delete PUNCH.CPM (ctrl-break menue Delete Punch File)
and enter:
A>stat con:=bat:
[now input is read from READER.CPM until the last stat command]
A>
[PUNCH.CPM contains now: ]
A>stat dsk:
A: Drive Characteristics
1480: 128 Byte Record Capacity
185: Kilobyte Drive Capacity
64: 32 Byte Directory Entries
64: Checked Directory Entries
128: Records/ Extent
8: Records/ Block
40: Sectors/ Track
3: Reserved Tracks
A>
A>stat con:=crt:
End of ZSIM.DOC