1This document describes only the features of the old version yaze-1.00. 2But read this document because the features which are described here are 3also the features of the new yaze-ag-2.20 (this version). 4 5If you want to read about the new features of yaze-ag-2.20 use yaze-ag.doc. 6 7------------------------------------------------------------------------------- 8 9Yet Another Z80 Emulator (yaze-1.00) 10==================================== 11 12Contents 13======== 14 15 1. Introduction 16 2. Installation and Testing 17 3. Command-line options 18 4. Bootstrap file formats 19 5. Creating bootstrap files 20 6. CP/M disks 21 7. Benchmarks 22 8. Emulating embedded systems 23 9. Software sources 24 10. Why? 25 26 271. Introduction 28================ 29The README file gives a brief overview of what yaze is and why you 30might want to install it. This package assumes you have a unix system 31and that a number of common tools are available on it. 32 33 342. Installation and Testing (yaze-1.00) 35======================================== 36First you need to uncompress and untar the archive file, which you 37have probably already done if you are reading this. Go to the 38directory under which you want yaze to be unpacked, 39e.g. /usr/local/src. Then, if you have gnu-tar, type 40'tar xzf yaze-1.00.tar.gz' and otherwise 41'zcat yaze-1.00.tar.gz | tar xf -'. Change to the newly created 42directory yaze-1.00 and edit the Makefile. 43 44If GNU Readline is available on your system you will probably want to 45use it with yaze. Readline comes together with most interactive 46programs from the Free Software Foundation, such as gdb and bash. It 47permits command-line editing, history recall and (unix-) filename 48completion when used with yaze and cdm. The include files and library 49should be somewhere where your compiler can find them, otherwise you 50will have to add the paths to the Makefile. 51 52When you have customized the Makefile, try 'make'. Yaze was developed 53under SunOS5 and I have briefly tried it under Linux and FreeBSD. You 54will have to do some hacking if your system does not support the 55termios tty interface. You will have to do a lot of hacking if your 56system does not have memory mapped files via mmap() and munmap(). 57 58Once you have a clean make of yaze you can try it out. WARNING! Yaze 59disables all tty interrupts by default, so if you only have 1 terminal 60session available it may be difficult to regain control if yaze goes 61haywire. You may want to add the line 'interrupt ^C' (or some other 62character) to .yazerc to be safe (though you cannot use that character 63under CP/M then). Under X11 or screen this is not a problem because 64you can kill a runaway process from a different window. The normal 65way to leave yaze is to type 'sys quit' at the CP/M A> prompt. 66 67Start yaze by typing 'yaze -v'. This will use the defaults and give a 68verbose account of the system configuration. 69 70--------------------------------------------------------------------------- 71 $ yaze -v 72 73 Yet Another Z80 Emulator version 1.00, Copyright 1995 Frank D. Cringle. 74 yaze comes with ABSOLUTELY NO WARRANTY; for details 75 see the file "COPYING" in the distribution directory. 76 77 Running 'yaze.boot' 78 bootfile: /usr/local/lib/yaze.boot 79 startup file: .yazerc 80 basepage: d8 81 ccp_base: d800 82 bdos_base: e000 83 bios_base: ee00 84 bios_top: ee66 85 dptable: fd90 86 dirbuf: ff80 87 88 A> 89--------------------------------------------------------------------------- 90 91This shows the default values of various parameters which can be 92overridden on the command line. The bootfile will be described in more 93detail later. The basepage is where the CP/M ccp is placed, and the 94other addresses follow from that. The ccp is 800h bytes long and the 95bdos is 0e00h long. The bios occupies only 66h bytes in the Z80 ram, 96because all we need is the jump table for 17 vectors and the targets 97for these jumps to transfer control to the real bios executing on the 98host cpu. The space between bios_top and dptable is available for 99disk allocation vectors. Dptable has space for the maximum possible 10016 disk parameter headers and disk parameter blocks. The dirbuf is 101shared between all disks as in standard CP/M. 102 103Yaze reads the file .yazerc when it starts up and the distributed 104.yazerc contains: 105 mount a test 106 go 107 108The first line mounts the unix directory 'test' as CP/M drive A and 109the second line starts the emulator. Commands such as 'mount' and 110'go' can also be entered interactively when the emulator is in 111monitor mode. It starts out in monitor mode (unless the command line 112or startup file contain 'go'), and you can get back to monitor mode by 113executing the CP/M command 'sys'. This command is found in the file 114sys.com in the test directory. It is difficult to get out of the 115emulator if you do not keep a copy of sys.com accessible on a mounted 116disk. 117 118If you execute 'sys' without arguments it takes you into monitor mode, 119which is indicated by the $> prompt. Here a number of commands are 120available, including a help command. 121 122--------------------------------------------------------------------------- 123 A>sys 124 125 $>help 126 help Display this text or give help about a command 127 ? Synonym for `help' 128 attach Attach CP/M device to a unix file 129 detach Detach CP/M device from file 130 mount Mount a unix file or directory as a CP/M disk 131 umount Unmount a CP/M disk 132 create Create a new disk 133 interrupt Set user interrupt key 134 go Start/Continue CP/M execution 135 ! Execute a unix command 136 quit Terminate yaze 137 time Display elapsed time since last `time' command 138 $> 139--------------------------------------------------------------------------- 140 141More information about each command is available by entering 142'help command'. 143 144--------------------------------------------------------------------------- 145 $>help help 146 help <cmd> displays more information about <cmd> 147 148 $>help attach 149 attach without arguments lists the current attachments 150 attach <physdev> <file> attaches <physdev> to the unix <file>, 151 where <physdev> is one of ttyin, ttyout, 152 crtin, crtout, uc1in, uc1out, rdr, 153 ur1, ur2, pun, up1, up2, lpt, ul1 154 155 $>help detach 156 detach <physdev> closes the file attached to <physdev> 157 (see attach) 158 159 $>help mount 160 mount without arguments lists the mount table 161 mount -v lists the mount table verbosely 162 mount <drive> <file> mounts <file> as CP/M disk <drive> 163 (a letter from a..p). 164 If <file> is a plain file it must contain a CP/M filesystem. 165 If <file> is a unix directory its contents may be accessed 166 as a read-only CP/M disk 167 mount -r <drive> <file> mounts the <file> read/only. 168 169 $>help umount 170 umount <drive> closes the file associated with <drive> 171 and frees the resources 172 173 $>help create 174 create {flags} <file> {size} creates a unix <file> initialized as a 175 CP/M disk of size {size} (default 1MB). 176 -b <block size> default 1024 if size < 256K, else 2048 177 -d <# dir entries - 1> default 1023 178 -o <track offset> default 0 179 -s <sectors per track> default 26 180 create <file> 256256 create a raw SSSD disk image 181 182 $>help interrupt 183 interrupt <key> makes <key> interrupt CP/M back to the monitor 184 <key> may be a 2-digit hex number or ^x where x is one of a..z[\]^_ 185 ^@ makes CP/M uninterruptible (from the keyboard) 186 interrupt without an argument displays the current setting 187 188 $>help go 189 Start/Continue CP/M execution 190 191 $>help ! 192 ! escape to a unix shell 193 !cmd execute unix cmd 194 195 $>help quit 196 Terminate yaze 197 198 $>help time 199 displays elapsed, user and system time in seconds, 200 along with simulator options 201--------------------------------------------------------------------------- 202 203Monitor commands can be abbreviated (e.g. 'm' for 'mount'), except 204'quit' must by typed in full. 205 206 207The yaze-1.00/test directory contains a number of .com files (CP/M 208executables). The quickest way to test the installation is to execute 209prelim.com 210 211--------------------------------------------------------------------------- 212A>dir 213PRELIM .Z80 | ZEXLAX .PL | ZEXALL .Z80 | ZEXDOC .Z80 214PRELIM .COM | ZEXALL .COM | ZEXDOC .COM | SAVAGE .PAS 215SAVAGE .COM | SYS .AZM | SYS .COM 216A>prelim 217Preliminary tests complete 218A> 219--------------------------------------------------------------------------- 220 221Zexall.com and zexdoc.com are both derived from zexlax.pl. They are 222designed to exhaustively compare Z80 implementations. This is done by 223executing all practicable instructions for as wide a range of operands 224as feasible, and calculating a 32-bit crc of the resulting machine 225states. If the crc values of two implementations match we can be 226confident that they are, for practical purposes, identical. 227 228Zexall and zexdoc differ only in that zexall tests all 8 bits in the 229flag register for all instruction whereas zexdoc only tests the 230documented flag values. 231 232The expected crc values are those produced by a Mostek MK3880-4 CPU, 233date code 8010, and confirmed on an Epson PX-8. Zexall and zexdoc run 234about 3.25 hours each on a 4MHz Z80. 235 236Savage.com is a simple benchmark compiled from savage.pas with 237Pascal/MT+. Its execution time depends almost exclusively on the 238quality of the run-time library. Also, Pascal/MT+ only uses 8080 239instructions, so it does not say anything about the speed of Z80 240extensions. 241 242'make install' puts the binaries in BINDIR (default: /usr/local/bin), 243the manual pages in MANDIR (default: /usr/local/man/man1) and the 244bootstrap file in LIBDIR (default: /usr/local/lib). 245 246 2473. Command-line options 248======================== 249New command line options for yaze-ag-2.01 are described in yaze-ag.doc 250chapter 5. 251 252Usage: yaze {flags} {commands} 253 -b <file> boot from this file 254 -l <xxxx> load bootfile at given (hex) address 255 -p <xx> base page (top 2 hex digits of ccp base) 256 -s <file> startup file 257 -v verbose 258 -z <xxxx> (hex) address of z3env (if desired) 259 260If yaze is run without command-line options it loads the bootstrap 261file from /usr/local/lib/yaze.boot or, if that does not exist, from 262./yaze.boot to address 0d800h and relocates the contents to fit that 263base address. It then looks for a "run control" file .yazerc in the 264current directory or, if not found there, $(HOME)/.yazerc. If an 265rc-file is found it is expected to contain a list of monitor commands, 266typically mount, attach and go, and these commands are executed. 267Finally, any remaining values on the command line are also interpreted 268as monitor commands and executed. 269 270If a "go" command was seen in the rc-file or on the command line the 271emulator is started, otherwise control is passed to the monitor. 272 273A different bootstrap file can be specified on the command line with 274the -b option. The base page (top 2 hex digits of the ccp location) 275can be specified with the -p option. The bootstrap file can be loaded 276at an address other than the base page with the -l option. The 277required contents of bootstrap files are explained in the next 278section. 279 280A different startup file from .yazerc can be specified with the -s 281option. Space (1 Kbyte) can be reserved for a Z-system environment at 282an address given by the -z flag. The -v flag produces a configuration 283summary. 284 285Any monitor commands on the command line must be quoted if they are 286more than one word. Example: 287 yaze "mount b foo" "attach lpt print.out" 288 289 2904. Bootstrap file formats 291========================== 292A bootstrap file contains the Z80 machine code that is executed when 293the emulator starts. Yaze accepts 3 types of bootstrap file: 294a) arbitrary code that is loaded to a specified address and executed, 295b) a single (non-relocatable) copy of CCP+BDOS that is loaded to the 296 CCP base address and started via the BIOS cold boot entry-point and, 297c) a double (and thus relocatable) copy of the CCP+BDOS that is 298 loaded to the CCP base and if necessary suitably relocated before 299 being started via the BIOS cold boot entry-point. 300 301An address given via the -l parameter on the command line indicates 302the first type of file. It might be a bootstrap loader which contains 303a clone CP/M for which extra environment data must be set up before 304jumping to the BIOS cold boot routine. Control is passed to the 305bootstrap at the address to which it was loaded, with the desired CCP 306base address in register HL. 307 308If no -l parameter is present on the command line the size of the boot 309file is used to differentiate cases b and c, and subcases. The CCP 310and BDOS might have been assembled from source to run at a fixed 311address, in which case the file should be 5632 bytes long (1600h). 312Alternatively, the file might have been saved after executing movcpm 313on a real CP/M 2.2 system. In this case it will be between 7808 and 31411263 long and CCP will found at offset 880h in the file. 315 316If the input file is twice the length of CCP+BDOS, i.e. 11264 bytes 317long, it is assumed to contain 2 copies of the same source, assembled 318to run at different 1K boundaries. It does not matter what the 319addresses actually are, yaze takes one copy and adjusts the addresses 320(any bytes that differ between the 2 copies are assumed to be the high 321byte of an address) to fit the final location. Similarly, if the 322input file is longer than 17407 it is assumed to contain 2 CP/M 2.2 323saves after movcpm with different system sizes. 324 325 3265. Creating bootstrap files 327============================ 328The bootstrap file distributed with yaze, yaze.boot, is a 2-copy file 329containing Don Kirkpatrick et al's D&J ZCPR as CCP and SUPRBDOS by 330Herman ten Brugge and Benjamin Ho as BDOS. These programs claim to be 331freely redistributable. They are both on the Walnut Creek CP/M CDROM 332and are also in the oak archives. 333 334I assembled both programs twice, once with P2DOS (the BDOS base 335address) set to 0C800H and once with it set to 0CC00H. The resulting 336hex files were loaded with mload and concatenated together, making 337sure to pad the lengths of the individual components to 800H/0E00H. 338I added an instruction to strip the high bit from console output 339characters in SUPRBDOS, because I do not think this should be done in 340the BIOS - a debatable position because DR's documentation is 341inconclusive on the issue and the original BDOS does not strip the 342bit. I also disabled the "delay 256 characters" feature in SUPRBDOS, 343because it was interfering with benchmarking when running yaze with 344input redirection. 345 346 347An easy way to make a boot file on a real CP/M system is: 348 B>movcpm 64 * 349 350 CONSTRUCTING 64k CP/M vers 2.2 351 READY FOR "SYSGEN" OR 352 "SAVE 34 CPM64.COM" 353 B>save 34 a:cpm64.com 354 355Then transfer cpm64.com as a binary file to your unix system and 356 yaze -b cm64.com 357 358 Yet Another Z80 Emulator version 1.00, Copyright 1995 Frank D. Cringle. 359 yaze comes with ABSOLUTELY NO WARRANTY; for details 360 see the file "COPYING" in the distribution directory. 361 362 Running 'cpm64.com' 363 364 A> 365 366This works because the default basepage is 0E4H and the CCP is located 367at 0E400H in a 64K CP/M system. You must take this into account when 368using other system sizes, e.g. 369 yaze -b cpm63.com -p e0 370 371 3726. CP/M disks 373============== 374CP/M version 1.4 used single-sided single-density 8" floppy disks with 37577 tracks of 26 128 byte sectors each. This format and the 376arrangement of data within it remained the standard distribution 377format for CP/M 2.2, but other formats were now also supported. This 378had advantages and disadvantages. Double density, double sided disks, 379hard disks, other floppy sizes etc. could be used, but there was no 380standard method of determining what the format of a particular disk 381was. Tables had to be built into the BIOS which matched the disk in 382question. 383 384Yaze does not attempt to access CP/M disks directly. It assumes that 385it is accessing a unix file containing a copy of a CP/M disk. The 386file can contain either a raw copy of a standard single-sided 387single-density disk (with sector skew = 6), or a de-skewed copy of any 388format with a descriptive header. The header is recognized when the 389file starts with the string "<CPM_Disk>" (a sort of "magic number"). 390 391The disk header occupies the first 128 bytes of the file and has the 392format: 393 394 0 - 9 <CPM_Disk> 395 10 - 31 a null-terminated ascii comment (may be empty) 396 32 - 33 sectors per track 397 34 block shift factor 398 35 block mask 399 36 extent mask 400 37 - 38 disk size max 401 39 - 40 directory max 402 41 al0 403 42 al1 404 43 - 44 check size (always zero) 405 45 - 46 track offset 406 47 - 127 unused (zeros) 407 408CP/M aficionados will recognize bytes 32 - 46 as a copy of the disk 409parameter block. 2-byte values are stored little-endian (low-byte 410first). The check size is set to zero because yaze does not allocate 411space for a check vector when mounting a disk. Instead sys.com resets 412the disk system whenever control is returned from the monitor to CP/M, 413in case a disk was unmounted or remounted. It is the responsibility 414of the user not to mess with disks from a different process, at least 415not without executing sys.com (or diskrst.com) before resuming a 416running yaze session. 417 418The raw contents of the disk follow the header. The sectors must be 419arranged sequentially, i.e. any sector skew must be removed when 420copying a real disk into a <CPM_Disk> file, because yaze sets the 421sector translation table address to zero in the disk parameter header. 422 423If the file does not begin with "<CPM_Disk>" and is exactly 256256 424bytes long (77*26*128), it is assumed to be an exact copy of a SSSD 425disk. 426 427Empty disks can be created by the yaze monitor and by cdm. When a 428disk is created only the directory and the last sector of the disk are 429actually written out. This has the advantage that unallocated data 430does not occupy space in the unix file system. For example, if we 431create an 8MByte disk (the maximum size supported by standard 432CP/M-2.2), we can see that it only occupies 56KBytes of physical disk 433space. 434 435 A>sys 436 437 $>create disk 8m 438 $>mount b disk 439 $>mount -v 440 A: r/o test/ 441 dph=FD90, xlt=0000, dirbuf=FF80, dpb=FDA0, csv=0000, alv=FA66, spt=0100 442 bsh=05, blm=1F, exm=01, dsm=0100, drm=07EF, al=FFFF, cks=0000, off=0000 443 B: r/w disk 444 dph=FDAF, xlt=0000, dirbuf=FF80, dpb=FDBF, csv=0000, alv=FA87, spt=001A 445 bsh=04, blm=0F, exm=00, dsm=0FFF, drm=03FF, al=FFFF, cks=0000, off=0000 446 $>quit 447 448 % du -sk disk 449 56 disk 450 % ls -sl disk 451 112 -rw-rw-r-- 1 fdc grp 8388736 Oct 9 21:32 disk 452 453A disadvantage of this method is that if the unix filesystem becomes 454full or the user's disk quota is exceeded when yaze tries to write 455data into a not-yet allocated part of the file, the process will be 456aborted with a SIGSEGV. It might be possible to extend yaze with a 457signal handler and longjmp to cover this case, but that is not in 458version 1.00. 459 460 461There is no specific support in this package for transferring data 462from existing CP/M disks into a form suitable for use with yaze. It 463is highly dependent on the available hardware and interfacing 464possibilities. If the individual files from the disk can be got into 465a unix directory (maybe via serial transfer with kermit or 466x/y/zmodem), that directory can be mounted by yaze as a read-only 467pseudo disk and its contents used from there or copied into a 468<CPM_Disk> file. If direct access to a floppy drive is available it 469is probably best to write a small program to transfer the contents 470with a header prepended and the sectors deskewed. With luck it may be 471possible to use dd to copy the disk into a file. Then generate a 472<CPM_Disk> of the same format with yaze or cdm, chop the unused data 473part with tail(1) and cat(1) the disk's data onto it. 474 475 4767. Benchmarks 477============== 478 479SAVAGE.COM 480 yaze/50MHz supersparc: 11.6 secs (~ 22.4 MHz) 481 4.0MHz Z80: 65 secs 482 2.5MHz Z80 (PX-8): 105 secs (~ 2.48MHz) 483 484 485ZEXALL.COM 486 yaze/50MHz supersparc: 1855 secs (~ 25.2 MHz) 487 4.0MHz Z80: 11688 secs 488 2.5MHz Z80 (PX-8): 19114 secs (~ 2.45MHz) 489 490 4918. Emulating embedded systems 492============================== 493The talk up to here has been of using yaze to run CP/M. If you want 494to use it to emulate some other system you will have to add that 495system's interaction with the outsize world to the source code. The 496instruction set emulator is in simz80.c. I tried to make all 497references to memory and I/O ports via the macros that are defined in 498simz80.h. These could be modified or replaced by function calls to 499reflect the behaviour of a particular embedded system. If the target 500system uses interrupts, that logic would have to be added from 501scratch. 502 5039. Software sources 504==================== 505(/cdrom/cpm_cdrom is the path to the Walnut Creek CP/M CDROM on my 506system). 507 508SUPRDOS from /cdrom/cpm_cdrom/cpm/bdos/suprdos2.lbr (length = 90112) 509 510ZCPR from /cdrom/cpm_cdrom/demon/zcpr-d-j.com (length = 32896) 511(same as ftp.demon.co.uk:/pub/cpm/zcpr-d&j.com) 512 513 51410. Why? 515======== 516Here are answers to some questions that I would probably be asking if 517I were reading this. 518 519Q. Why did you base this on CPM-2.2 rather than CPM-3? 520A. I do not have access to a CPM-3 system, so I could not have tested 521 the implementation. 522 523Q. Why did you write it all from scratch, rather than starting with one 524 of the other free emulators? 525A. "Not invented here", I guess. Starting from scratch meant that I 526 could do what I liked with the code, including putting it under the 527 GPL, without consulting others. Also, I have been messing with 528 this for years on and off. I was not aware of other emulators when 529 I started. 530 531Q. Why didn't you rewrite CCP and BDOS in C and let them run on the 532 host cpu? 533A. That was the original plan, particularly while I thought there was 534 no free bdos available. Partly because I want to finally get this 535 stuff out of the door and partly because it is a lot of work to do 536 right, I have left it for now. 537 538Q. Why no built-in debugger? 539A. My main aims were emulation accuracy and speed. As it is, you can 540 run a CP/M debugger like zsid or z8e in the emulator. If that is 541 not enough, you can run yaze under gdb or put hooks in the yaze 542 source to analyse particularly tricky cases. 543 544Q. What's all this perl stuff? 545A. I make no apology for using perl as a super-macro-processor to 546 generate simz80.c and zexall.z80 / zexdoc.z80. You do not need 547 perl to install yaze, because the output files are provided, but 548 you will need it if you want to experiment. 549 550 Simz80.pl includes 5 booleans which define how simz80.c is 551 structured - see the source for more documentation. A good way to 552 chew up machine cycles is to generate all 32 possible variants and 553 benchmark them by running zexall.com. 554 555 Zexlax.pl fills in pseudo-random initial states in the test cases. 556 Be careful if you change anything - you will have to run the new 557 version on a reference Z80 to find the expected CRC values. 558 559 560*** Local Variables: *** 561*** mode:outline *** 562*** outline-regexp: "[0-9]+\\." *** 563*** End: *** 564