home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / emulate / spectrum.lha / Spectrum.doc < prev    next >
Text File  |  1993-01-25  |  41KB  |  1,083 lines

  1.  
  2.  
  3.             Sinclair ZX Spectrum Emulator V1.6     25 Jan 1993
  4.             ----------------------------------
  5.  
  6.  
  7. This program emulates a Sinclair ZX Spectrum 48-kbyte z80-based computer on
  8. any Amiga computer.
  9.  
  10.     +-------------------------------------------------------------------+
  11.     | IMPORTANT:  You need to already own a Spectrum to be able to use  |
  12.     | this program.  This is because I am not taking the risk of        |
  13.     | distributing the Spectrum ROM code.  I think that would probably  |
  14.     | be illegal.  Therefore this archive does not include the Spectrum |
  15.     | ROM code. --- You should supply it independently.            |
  16.     +-------------------------------------------------------------------+
  17.  
  18. The files in this archive may be distributed anywhere provided they are
  19. unmodified and are not sold for profit.  Ownership remains with the author,
  20.  
  21.     Peter McGavin, 86 Totara Crescent, Lower Hutt, New Zealand.
  22.     e-mail: peterm@maths.grace.cri.nz    (note changed e-mail address).
  23.  
  24.  
  25. I assume you have enough knowledge to manipulate binary files and to transfer
  26. data over a serial line without help.  If you don't know what I'm talking
  27. about, don't try this program.
  28.  
  29.  
  30. Spectrum-00 is an executable for 68000-based Amigas only.
  31.  
  32. Spectrum-10 is for 68010-based Amigas, but also works on higher processors.
  33.  
  34. Spectrum-20 is optimised for 68020/30/40...-based Amigas with fast memory.
  35.  
  36. Spectrum-00-special is for 68000-based Amigas.  It is faster and dangerous.
  37.  
  38.  
  39. The Spectrum-00-special version takes some shortcuts to get some extra speed.
  40. Some games will run 2 or 3 times faster in Spectrum-00-special than in
  41. Spectrum-00, but because of the shortcuts, not all programs will work.  In
  42. the special version:
  43.  
  44.     o  Self-modifying z80 code does not work at all.  This affects some
  45.         games.  It also means that you will only be able to run one
  46.         program and then quit.  If you try to load a second Spectrum
  47.         program, without quitting Spectrum-00-special and re-running
  48.         it first, it very probably won't work.
  49.  
  50.     o  Code is optimised for faster animated graphics and scrolling, at
  51.         the expense of speed when the display is static, so you will
  52.         get faster animated games and slower ray-tracing  :-)
  53.  
  54.     o  The ROM is unprotected.  Note that the standard Spectrum ROM
  55.         corrupts itself.  In particular, location 0 usually gets
  56.         overwritten very quickly, so that NEW does not work any more.
  57.  
  58. Do not try to develop or write Spectrum programs with Spectrum-00-special,
  59. because you will probably lose your work.  It is provided only because it is
  60. significantly faster for running some animated Spectrum games.
  61.  
  62. All the programs require the file "spectrum.rom" (not supplied) in the current
  63. directory, or they will not load.
  64.  
  65. The emulator uses the dreaded move-sr instruction after almost every z80
  66. instruction emulated.  It ran 30-40% slower when I tried replacing the
  67. move-sr instruction with a call to GetCC()!  This is quite exceptional ---
  68. with most programs you wouldn't notice the difference.  Therefore I have
  69. supplied a 68010 version which uses move-ccr instead of move-sr.
  70.  
  71. The Spectrum-20 version uses 68020 addressing modes which are not available
  72. on lower processors.
  73.  
  74. The program has been tested on a 3.5 Mbyte Amiga 500 and on a 2 Mbyte Amiga
  75. 3000 (but it uses only about 300 kbytes).
  76.  
  77. I developed the code, entirely in assembler, in my spare time using z80
  78. emulation code based (originally) on Ulf Nordquist's CP/M emulator (Fred Fish
  79. disk 165).  I have fixed several bugs in the z80 emulation code, and made it
  80. more than twice as fast, but there are still some (very hard to find) bugs.
  81.  
  82.     
  83. Features:
  84. ---------
  85.  
  86. The following Spectrum features are implemented:
  87.  
  88.     screen output in the same resolution and colours as a real Spectrum
  89.         --- includes bright, reverse and flash attributes, and border
  90.         colour (looks much better than the old TV!)
  91.  
  92.     keyboard implemented at the z80 "in" instruction level.  Note that
  93.         like a real Spectrum you have to hold the key down until it
  94.         registers.  Because the emulator is running slower, you might
  95.         have to hold keys down longer.  More often, you might have to
  96.         hold your fingers off the keyboard for longer.  Make sure the
  97.         Spectrum window is active when you start to type.  See
  98.         Appendix 1 for key map.
  99.  
  100.     kempston joystick implemented at the Z80 "in" instruction level.  This
  101.         uses the rear Amiga gameport.  Note that the joystick is
  102.         active only when the Spectrum window is active.  If another
  103.         Amiga program is currently using the joystick, you will get a
  104.         retry/no-joystick requester.
  105.  
  106.     sound implemented using 2 techniques.  Calls to the "beeper" routine
  107.         at $03b5 in the Spectrum rom are trapped and the sound is
  108.         emulated at the exact same frequency and duration.  Sound is
  109.         also reproduced when a Spectrum program outputs to z80 port
  110.         254.  In this case the pitch and duration may or may not
  111.         sound correct, depending on the Spectrum program and the speed
  112.         of the Amiga you are using.
  113.  
  114.     cassette tape loading, if you have a sound sampler capable of at least
  115.         20 kHz sampling rate attached to your parallel port.  This is
  116.         implemented by trapping calls to the "ld-bytes" routine at
  117.         $056b in the Spectrum rom.  Note that copy-protected games
  118.         with custom loaders cannot always be loaded this way.
  119.  
  120. It is possible to save to and load from amiga disk files.
  121.  
  122.  
  123.  
  124. That Missing File:
  125. ------------------
  126.  
  127. As already mentioned, a vital file is missing.  You must supply an image of
  128. the Spectrum's ROM in the file "spectrum.rom".  The file must be exactly
  129. 16384 bytes long and must contain exactly the same byte sequence as memory
  130. locations 0..16383 in the Spectrum.  There are several ways to get this
  131. across to your Amiga, including:
  132.  
  133.     Use the Sinclair Interface 1 serial port connected to the Amiga's
  134.     serial port.  The data can be transferred using a small BASIC program
  135.     on the Spectrum, then captured on the Amiga with either another small
  136.     program or a comms program.
  137.  
  138.     Use a Spectrum disk drive system that writes IBM-format sectors, then
  139.     read the diskettes on your Amiga using MSH (Fred Fish disk 382) or
  140.     CrossDOS (commercial) and a sector editor like DiskX (Fred Fish disk
  141.     158).  An MGT PLUS D disk drive will work for this.
  142.  
  143.     Find a program that will read Spectrum cassette tapes through an Amiga
  144.     sound sampler, writing the data to a disk file as it goes.  Kristian
  145.     Nielson (e-mail bombadil@freja.diku.dk) has written a program that
  146.     will do this.  Try looking for specload.lzh at your local PD site.
  147.  
  148.     Find another Spectrum emulator that comes with the ROM code.  Rumour
  149.     has it that there is an Atari-ST Spectrum emulator comes with the ROM
  150.     code.
  151.  
  152. I'll leave it up to you to figure out how to get the data across.  You
  153. could always type it in :-)  There are several third-party books that list
  154. the code, e.g,
  155.  
  156.     "The Complete Spectrum ROM Disassembly" by Dr Ian Logan and Dr Frank
  157.     O'Hara, Melbourne House Software Ltd, ISBN 0 86161 116 0, or
  158.     ISBN 0 86759 117 X, 1983;
  159.  
  160.     "The Spectrum Machine Code Reference Guide" by Richard Ross-Langley,
  161.     Interface Publications, ISBN 0 907563 51 1, September 1983.
  162.  
  163. I believe that Spectrums have been sold with several slightly different ROMs,
  164. including Scandinavian and Argentinian internationalised versions.  Also
  165. various ROM patch hacks have been distributed around user-groups (requiring
  166. a personal ROM burner to apply).  Any ROM should work, but I have not been
  167. able to test them all.  A non-standard version should behave in the emulator
  168. exactly as if it was installed in a real Spectrum.
  169.  
  170. In fact you can supply any 16384-byte file containing valid z80 code and
  171. called spectrum.rom.  The emulator will transfer z80 control to location 0.
  172. Screen and keyboard hardware is programmed the same as a real Spectrum.
  173. (Once loaded, the first 16384 memory locations are readonly.)
  174.  
  175. Please don't ask me to e-mail spectrum.rom to you, because I won't.
  176.  
  177.  
  178.  
  179. Operation:
  180. ----------
  181.  
  182. You can start the emulator from either the Workbench or SHELL (or CLI).  There
  183. are no command-line parameters.
  184.  
  185. If you use the SHELL (or CLI), spectrum.rom must be in the current directory.
  186. From the workbench, spectrum.rom should be in the same directory as the
  187. program.
  188.  
  189. If the emulator can't find spectrum.rom, then it will display a requester
  190. saying so, and it will not run.
  191.  
  192. To use the ARP file requester, you must have arp.library installed in your
  193. LIBS: directory.
  194.  
  195. The emulator runs in its own custom screen and window.
  196.  
  197. The emulator does not disable multitasking, and it does not interfere with
  198. other tasks (except when loading from a sound sampler).  You can drag the
  199. screen down or click it to the back with the mouse, in the usual way.  (Grab
  200. the screen bar to the left of the window to pull it down.)
  201.  
  202. The emulator lowers its own priority to -5, otherwise it would significantly
  203. slow down other tasks.  Raising the priority back to 0 (e.g, with xoper or
  204. artm) does not significantly speed up the emulator on a standard system.
  205. Raising it higher will prevent most other tasks from running at all.
  206.  
  207. To exit the emulator, do any of the following:
  208.  
  209.     o  click the close box with the left mouse button;
  210.  
  211.     o  select "Quit..." from the Project menu, or
  212.  
  213.     o  press the ESC key.
  214.  
  215.  
  216.  
  217. Menus:
  218. ------
  219.  
  220. Project menu
  221.  
  222.     Reset...
  223.     Resets the z80, unless you cancel the requester that pops up.
  224.     This is like the Spectrum NEW command, but it works even when you
  225.     are running an "unbreakable" or "crashed" program.
  226.  
  227.     Load snapshot...  F1
  228.  
  229.     Loads a disk file that has been created with "Save snapshot",
  230.     restoring the state of the system to what it was when the snapshot
  231.     was made.  Any currently loaded Spectrum program is lost.  Uses
  232.     the ARP file requester.
  233.  
  234.     You can use "Load snapshot..." even if the Spectrum has "crashed",
  235.     or if you are running a Spectrum program which does not have a
  236.     "quit" option.
  237.  
  238.     Save snapshot...  F2
  239.  
  240.     Saves the current state of the emulator to a disk file.  The entire
  241.     state of the system is saved, including all 48 kbytes of Spectrum ram
  242.     and the state of the z80 processor.  Uses the ARP file requester.
  243.  
  244.     The format of a snapshot file is listed in Appendix 2.
  245.  
  246.     Help...         HELP
  247.  
  248.     Displays the "Spectrum.help" file, which is a diagram of a real
  249.     Spectrum keyboard.  You need about 70 kb of CHIP ram free for this.
  250.  
  251.     Quit...          ESC
  252.  
  253.     Quits the emulator.  (You get a chance to change your mind.)
  254.  
  255.  
  256. Settings menu
  257.  
  258.     LOAD/MERGE/VERIFY...
  259.  
  260.     Selects what happens when the emulator executes a Spectrum BASIC
  261.     LOAD, MERGE or VERIFY command.
  262.  
  263.     Note that this has nothing at all to do with "Load snapshot", which
  264.     always loads from disk.  What it does do, is to change the behaviour
  265.     of the standard Spectrum BASIC tape loading commands, which are
  266.     normally used to load, merge and verify BASIC programs, array data
  267.     and binary code, from cassette tape.
  268.  
  269.     In fact, this selects what happens when any program (including any
  270.     machine code program) calls the cassette tape loading routine in the
  271.     Spectrum rom.
  272.  
  273.     You have a choice of:
  274.  
  275.         Disk files
  276.  
  277.         Select a disk file using the ARP file requester.  The data
  278.         in the file is interpreted as if it is being read from cassette
  279.         tape.
  280.  
  281.         The first byte in the file is the "header" byte, then the raw
  282.         data, then the checksum byte.
  283.  
  284.         The Spectrum normally reads 2 blocks of data from cassette
  285.         tape, a "header" file followed by the "data" file.  These
  286.         should be stored in 2 separate disk files.  The emulator will
  287.         request both files.  I implemented it this way to allow support
  288.         for "headerless" files which are used by many Spectrum machine
  289.         code programs.
  290.  
  291.         Note that the Spectrum still thinks it is reading from cassette
  292.         tape, so you might see messages like "Start tape now", even
  293.         though it is reading from disk.
  294.  
  295.         If the file you select is not in the correct format, or if the
  296.         checksum is wrong, the Spectrum will usually just request the
  297.         same file again, without any messages, as if it read garbage
  298.         noise from cassette tape.
  299.  
  300.         ProSound
  301.  
  302.         Read data from a ProSound sound sampler connected to the
  303.         parallel port.
  304.  
  305.         Rombo
  306.  
  307.         Read data from a Rombo sound sampler connected to the parallel
  308.         port (the sampler that comes with MegaMIX Master software).
  309.         Please note that this option is untested.
  310.  
  311.         Other sampler
  312.  
  313.         Read data from any other kind of sound sampler connected to the
  314.         parallel port.
  315.  
  316.         The sampler must be capable of at least 20 kHz sampling rate
  317.         and it must be connected to the parallel port (not the game
  318.         port).
  319.  
  320.         You should be able to feed standard Spectrum cassette tapes in.
  321.  
  322.         Some copy-protected programs have custom loaders that will not
  323.         work in the emulator.
  324.  
  325.         It is possible to connect the Spectrum EAR output to the sound
  326.         sampler to transfer data directly from your Spectrum.  (Use a
  327.         SAVE command at one end, and a LOAD at the other.)
  328.  
  329.         Important: Interrupts on the amiga are disabled while you are
  330.         loading from a sound sampler.  This will interfere with other
  331.         tasks.  For example, a file transfer running in the background
  332.         will probably fail.  Please make certain that no other tasks
  333.         are writing to disk at the instant you start sampling!
  334.  
  335.         It seems as if the whole amiga has frozen while interrupts are
  336.         disabled.  To restore control, click the left mouse button.
  337.  
  338.     SAVE...
  339.  
  340.     Selects what happens when the emulator executes a Spectrum BASIC
  341.     SAVE command.
  342.  
  343.     Note that this has nothing at all to do with "Save snapshot", which
  344.     always saves to disk.  What it does do, is to change the behaviour
  345.     of the standard Spectrum BASIC SAVE commands, which are normally used
  346.     to save BASIC programs, array data and binary code, to cassette tape.
  347.  
  348.     In fact, this selects what happens when any program (including any
  349.     machine code program) calls the cassette tape saving routine in the
  350.     Spectrum rom.
  351.  
  352.     You have a choice of:
  353.  
  354.         Disk files
  355.  
  356.         Select a disk file using the ARP file requester.  The data
  357.         that would normally be written to cassette tape is written
  358.         to the selected file instead.
  359.  
  360.         The first byte in the file is the "header" byte, then the raw
  361.         data, then a checksum byte.
  362.  
  363.         The Spectrum normally writes 2 blocks of data to cassette
  364.         tape, a "header" file followed by the "data" file.  These
  365.         should be stored in 2 separate disk files.  The emulator will
  366.         request both files.  I implemented it this way to allow support
  367.         for "headerless" files which are used by many Spectrum machine
  368.         code programs.
  369.  
  370.         Note that the Spectrum still thinks it is writing to cassette
  371.         tape, so you might see messages like "Start tape, then press
  372.         any key".
  373.  
  374.         Audio
  375.  
  376.         Not implemented in V1.6.
  377.  
  378.  
  379.  
  380. More on Reading Cassette Tapes:
  381. -------------------------------
  382.  
  383. To load a cassette tape through your sound sampler, first select your sampler
  384. type in the Settings menu, then enter LOAD "" (that is, J followed by ALT/P
  385. twice, then RETURN).  Now start the cassette tape playing into your sound
  386. sampler.  If it is working, the screen border should flash colours, very much
  387. like your Spectrum, and the mouse pointer will be frozen.
  388.  
  389. The MERGE and VERIFY commands should also work, as should things like
  390. LOAD "" CODE, etc.
  391.  
  392. The border of the screen flashes different colours, exactly like a real
  393. Spectrum.  The colours mean:
  394.  
  395.     flashing yellow and blue:    the load is working
  396.     flashing red and white:        synchronising or not working
  397.     not flashing:            not working or tape not playing
  398.  
  399. If it doesn't work, try adjusting the volume and tone controls on the tape
  400. recorder.  If you have trouble, try adjusting the controls while sampling
  401. with software that came with your sampler.  Ideally, the input should be a
  402. square wave which fills the graphic display.  I found it necessary to have
  403. the volume control much lower than when using a real Spectrum, but it
  404. probably varies, depending on the sampler type.
  405.  
  406. You should be able to save directly from your Spectrum to the Amiga with a
  407. direct connection --- i.e, no cassette tape or recorder at all.  Use a SAVE
  408. command on the Spectrum and a corresponding LOAD command in the emulator.
  409.  
  410. Loading works by intercepting calls to the LD-BYTES routine at location
  411. $056b in the Spectrum ROM.  If a Spectrum program has its own loading
  412. routine, then it won't work.  Some copy-protected games and fast-loaders
  413. are like that, and they will not work.  On the other hand, some Spectrum
  414. programs call LD-BYTES to load headerless tape files.  Those programs
  415. should work fine.
  416.  
  417. If you have been using the parallel port recently (for printing or ParNet
  418. for example), you might get a requester asking you to please free up the
  419. parallel port.  Try shutting down the program that has allocated it.
  420.  
  421. The following sound samplers should be suitable, but I have not had the
  422. opportunity to test any except the first:
  423.  
  424.     o ProSound
  425.  
  426.     o Rombo (the one that comes with MegaMIX Master)
  427.  
  428.     o Perfect Sound (except that recent Perfect Sound samplers are
  429.         different from early versions and recent ones might not work)
  430.  
  431.     o Datel DSS
  432.  
  433.     o Future Sound
  434.  
  435. Documentation on how various samplers work seems to be hard to obtain.
  436. They all seem to be slightly different, especially the way stereo/mono
  437. modes are switched and different channels are selected.
  438.  
  439. For the technically minded, here are the cia register settings currently
  440. used by the loader:
  441.                 ProSound    Rombo        Other
  442.     setup ciab-ddra        4        7        6
  443.     setup ciab-pra        4,0 or none *    6        4
  444.     inter-sample ciab-pra    4,0,4,0        none        none
  445.     ciaa-prb input bias    $80        $80        $80
  446.  
  447.     * If bit 0 of ciab-pra is 0 then output 4 followed by 0 else none.
  448.  
  449. Note that the tape-loading routine disables interrupts for the whole time
  450. it takes to load a tape.  That greatly exceeds Commodore's recommended
  451. limit of 250 microseconds.  While interrupts are disabled, the mouse
  452. pointer freezes, the keyboard is locked out, all other tasks stop, and any
  453. data arriving at the serial port is lost.
  454.  
  455. Please make sure your disks are not busy when you start to load a tape.
  456. Especially make certain that no other program is writing to your hard disk!
  457.  
  458. If I knew another way to make it work, I'd do it that way.  As far as I am
  459. aware, all sound sampling software on the Amiga disables interrupts for
  460. excessive periods.  The Spectrum loader has to interpret the incoming data
  461. in real time, which is quite a lot more than just saving it to a buffer in
  462. memory.
  463.  
  464. To break out of the load routine without actually loading anything, press
  465. the left mouse button.  The Spectrum BREAK key (SHIFT/SPACE) won't work in
  466. this situation.
  467.  
  468. If the keyboard doesn't work after you break out with the left mouse
  469. button, it's probably because you accidently deselected the window (by
  470. clicking outside it).  Just click anywhere inside the Spectrum window
  471. and the keyboard will work again.
  472.  
  473. The load routine is based on code kindly provided by Kristian Nielson.
  474. It has been tested on both standard and accelerated amigas.
  475.  
  476.  
  477. General Notes:
  478. --------------
  479.  
  480. o   The emulator runs about 2 to 8 times slower than a real Spectrum, on a
  481.     standard 68000-based A500.  If you are the lucky owner of an Amiga 3000,
  482.     the emulator runs faster than a real Spectrum, but make certain it's
  483.     running out of FAST ram.  If you run it out of CHIP ram, then it's more
  484.     than twice as slow.  I'm afraid the 68000 doesn't have a built-in z80
  485.     emulation mode, and a 3.5 MHz z80 is much harder to emulate than a 6502
  486.     as used in the Commodore 64 and BBC microcomputers.  The Spectrum NEW
  487.     command takes 9.7 seconds on an A500, compared with about 2.0 seconds on
  488.     a real Spectrum, 1.8 seconds on an A3000 (in FAST static-column ram), and
  489.     1.6 seconds on a 33MHz Mega-Midget-Racer with 32-bit ram.  One person
  490.     reported to me that it runs about 3 times faster again on a 68040.
  491.  
  492.  
  493. o   This version of Spectrum uses the blitter to refresh the screen in
  494.     parallel with the emulator.  That is, it uses multi-processing.  Thus,
  495.     the overhead of a z80 instruction writing to the Spectrum's display file
  496.     is minimised.  Before you A3000 owners complain that the 68030 is faster
  497.     than the blitter for blitting, remember that while the blitter is
  498.     refreshing the screen, the 68030 is busy emulating the z80.  The program
  499.     uses QBlit() for concurrency, not OwnBlitter() which would block the z80
  500.     emulator.
  501.  
  502.  
  503. o   I've just about run out of ideas on how to significantly speed up the
  504.     code from what it is now.  One thought is to code some common ROM routines
  505.     in pure 68000.  Obvious candidates are the text output, scrolling, and
  506.     maskable interrupt routines.  Of course this would only speed up programs
  507.     that call the ROM, which excludes most games.  Also, It would probably be
  508.     illegal.  The major speed bottleneck used to be the z80 instruction
  509.     decode.  I've pretty well eliminated that by going to threaded code.  The
  510.     display routines are about as fast as I can get them.  Taking over the
  511.     machine and doing everything at the hardware level would probably give
  512.     only a slight speed improvement, and the program would become much less
  513.     friendly and less portable.
  514.  
  515.  
  516. o   In version 1.6, the following Spectrum features are NOT implemented yet:
  517.  
  518.     saving to cassette tape;
  519.  
  520.     bank roms (e.g, Interface 1);
  521.  
  522.     printing to a printer
  523.  
  524.  
  525. o   The following z80 features are NOT properly implemented:
  526.  
  527.     the z80 h processor flag;
  528.  
  529.     the z80 daa instruction (decimal adjust a) --- daa works properly only
  530.         immediately after add, sub, adc or sbc;
  531.  
  532.     the timer interrupt occurs after every 1500 branch, jump, call and
  533.         return z80 machine instructions, instead of every 20 ms.  On
  534.         accelerated amigas, interrupts will not occur any faster than
  535.         every 20 ms.
  536.  
  537.     updating of the flash attribute occurs every 24000 branch, jump, call
  538.         and return z80 instructions, instead of every 320 ms.  On
  539.         accelerated amigas, the flash speed will never be faster than
  540.         every 320 ms.
  541.  
  542.     interrupts and screen updates can occur only immediately after branch,
  543.         jump, call, return and halt z80 machine instructions.
  544.  
  545.     because the emulator is not real-time, the real interval between timer
  546.         interrupts and flash attribute updates depends on the nature
  547.         of the Spectrum program being run.
  548.  
  549.     there might still be rare problems executing certain long,
  550.     self-modifying z80 instructions located at exactly 32763..32766 in z80
  551.     memory, because of the 68000 addressing modes used to load instruction
  552.     operands;
  553.  
  554.     there is at least one other bug I haven't been able to track down yet.
  555.  
  556.  
  557. o   The emulator allocates and uses two sound channels.  If there are not
  558.     enough free channels, you get the option of running the emulator with no
  559.     sound.  If you have enough memory you can test this by running 3 copies of
  560.     Spectrum at once!
  561.  
  562.  
  563. o   Because it's running slower, maybe now you can get past that "impossible"
  564.     level in your favourite game.
  565.  
  566.  
  567. o   Now you can print Spectrum graphics by transferring to your Amiga.
  568.  
  569.  
  570. o   If you're cross-developing Spectrum software, now you can see which parts
  571.     need speeding up.
  572.  
  573.  
  574. o   I've tested it with several Sinclair Basic programs and all ran perfectly.
  575.  
  576.  
  577. o   I've tried lots machine-code programs and most work ok.  The following
  578.     programs seem to work ok in the emulator:
  579.  
  580.         Zeus Assembler and Monitor
  581.         Scrabble
  582.         Jetset Willy
  583.         Atic Atac
  584.         Jetpac
  585.         Tron
  586.         The Train Game
  587.         Backgammon
  588.         PSSST
  589.         Horace and the Spiders
  590.         Sam Spade
  591.         Draughts
  592.         Sam Stoat
  593.         3D Deathchase
  594.         Technician Ted
  595.         Kosmic Kanga
  596.         Monty Mole
  597.         Talk Chess
  598.         Horace Goes Skiing
  599.         Hungry Horace
  600.         Star Raid
  601.         Cyclone
  602.         Wheelie
  603.         Full Throttle
  604.         Mugsy
  605.         Dynamite Dan
  606.         Dynamite Dan II
  607.         Heathrow
  608.         IS Chess 48
  609.         Matchpoint
  610.         Max Headroom            no joystick
  611.         Spy vs Spy
  612.         Kong
  613.         The Alchemist
  614.         Daley Decathlon
  615.         Automania
  616.         Penetrator
  617.         Gyron
  618.         Alien8
  619.         Cyberun
  620.         KnightLore
  621.         Batman
  622.         Tomahawk
  623.         Fighter Pilot
  624.         Athena
  625.         Basil the Detective
  626.         Pacland
  627.         Orbix
  628.         Meteor
  629.         Manic Miner
  630.         Madmix
  631.         Kokotoni Wilf
  632.         Ikari Warriers
  633.         Gauntlet
  634.         Dustin
  635.         Ant Attack
  636.  
  637.  
  638.     St Bernard resets the Spectrum at the end of the first level.
  639.  
  640.     SabreWulf runs, except sometimes the rhino runs backwards (very
  641.     amusing).
  642.  
  643.     (If you know why either of these programs don't work, please tell me.)
  644.  
  645.     Note: The Amiga doesn't crash.  If a Spectrum program crashes, you can
  646.     either:  Quit the emulator and continue working on the Amiga, or:
  647.     Press F1 and load another snapshot.
  648.  
  649.     Note: Some of the above have not been tested since Spectrum v0.7 or v0.8.
  650.  
  651.     Another note: Some of the above programs won't load from tape, but they
  652.     will run if you can create a snapshot file somehow (e.g, Mirage Microdriver
  653.     and serial port).
  654.  
  655.  
  656. o   One problem I have had with snapshotting games by transferring a snapshot
  657.     file from the real Spectrum to the amiga, is as follows:  If there is
  658.     non-standard hardware in your real Spectrum (like a non-standard joystick or
  659.     disk drive), and the program knows about the special hardware, then the
  660.     program might have already done a hardware test (before you made the
  661.     snapshot) that makes it believe the special hardware exists permanently.
  662.     Then, when run under the emulator, the program tries to access the
  663.     non-existent hardware and behaves erratically.
  664.  
  665.     What is wrong is that the program was started in one environment (the real
  666.     Spectrum with add-ons) and is now running in another (the plain Spectrum
  667.     emulator).  For example, if your program behaves as if the joystick button
  668.     is continuously pressed (when run in the emulator), maybe it is because
  669.     you made the original snapshot from a Spectrum which has non-standard
  670.     joystick hardware.  See if you can disconnect the joystick interface and
  671.     reload the original program from tape before you make a snapshot.
  672.  
  673.  
  674. o   If the keyboard, joystick and/or menus do not respond at all, well,
  675.     then...  er...  umm... --- try clicking in the window  :-)
  676.  
  677.  
  678. o   I am not supplying the source of the emulator yet.
  679.  
  680.  
  681. o   Please report bugs to peterm@maths.grace.cri.nz.  I'd much prefer bug
  682.     reports like "the `or' instruction doesn't zero the carry flag" to
  683.     "Dan Dare doesn't work".
  684.  
  685.  
  686.  
  687. Appendix 1:  The keyboard:
  688.  
  689. The Spectrum has a weird way of mapping functions to keys that doesn't
  690. translate nicely to the Amiga.  To get a "[" on a real Spectrum, for example,
  691. you press CAPS-SHIFT and SYMBOL-SHIFT together followed by SYMBOL-SHIFT and F.
  692. In the emulator, you do the same thing except CAPS-SHIFT is either of the
  693. SHIFT keys and SYMBOL-SHIFT is either of the ALT keys.  Pressing "[" on the
  694. Amiga keyboard won't work.
  695.  
  696. The following table lists the Amiga key(s) corresponding to each Spectrum key:
  697.  
  698.     Amiga key        Spectrum key
  699.  
  700.     0..9            0..9
  701.     keypad 0..9        0..9
  702.     A..Z            A..Z
  703.     SPACE            SPACE
  704.     RETURN or ENTER        ENTER
  705.     either SHIFT key    CAPS-SHIFT
  706.     either ALT key        SYMBOL-SHIFT
  707.  
  708. The following special Amiga keys correspond to Spectrum key combinations.
  709.  
  710.     Amiga key        Spectrum key combination
  711.  
  712.     .            SYMBOL-SHIFT/M
  713.     ,            SYMBOL-SHIFT/N
  714.     ;            SYMBOL-SHIFT/O
  715.     -            SYMBOL-SHIFT/J
  716.     =            SYMBOL-SHIFT/L
  717.     keypad (        SYMBOL-SHIFT/8
  718.     keypad )        SYMBOL-SHIFT/9
  719.     keypad /        SYMBOL-SHIFT/V
  720.     keypad *        SYMBOL-SHIFT/B
  721.     keypad -        SYMBOL-SHIFT/J
  722.     keypad +        SYMBOL-SHIFT/K
  723.     keypad ENTER        ENTER
  724.     keypad .        SYMBOL-SHIFT/M
  725.     left arrow        SHIFT/5
  726.     down arrow        SHIFT/6
  727.     up arrow        SHIFT/7
  728.     right arrow        SHIFT/8
  729.  
  730. ESC quits the emulator (unless you cancel the requester that comes up).
  731.  
  732. HELP displays the Spectrum.help file, which is a diagram of the real Spectrum
  733. keyboard.  (You need about 70 kb of CHIP ram free for this.)
  734.  
  735. F1 brings up the load snapshot requester (provided arp.library is installed).
  736.  
  737. F2 brings up the save snapshot requester (provided arp.library is installed).
  738.  
  739. F3 changes the sampler type for cassette tape loading.
  740.  
  741. All the other Amiga keys do nothing.
  742.  
  743.  
  744.  
  745. Appendix 2:  Snapshot file format:
  746.  
  747. This format is based on the format used by the Mirage Microdriver "Dump"
  748. command.  Snapshot files are always 49179 bytes long.  Note that in the table,
  749. the byte offset starts from 0, not 1.
  750.  
  751.     Byte offset into file        Value
  752.  
  753.     0                i  register
  754.     1                l' register
  755.     2                h' register
  756.     3                e' register
  757.     4                d' register
  758.     5                c' register
  759.     6                b' register
  760.     7                f' register
  761.     8                a' register
  762.     9                l  register
  763.     10                h  register
  764.     11                e  register
  765.     12                d  register
  766.     13                c  register
  767.     14                b  register
  768.     15                iy low register
  769.     16                iy high register
  770.     17                ix low register
  771.     18                ix high register
  772.     19                bit 2 is set if interrupts are enabled
  773.     20                r register
  774.     21                flags register
  775.     22                a register
  776.     23                sp low register
  777.     24                sp high register
  778.     25                interrupt mode (0, 1 or 2)
  779.     26                border colour in low 3 bits
  780.     27..49178            48 kbytes ram dump
  781.  
  782.  
  783.  
  784. Appendix 3:  Other Spectrum Emulators:
  785.  
  786.  
  787. When I started this project I did not know of any other Spectrum emulators.
  788. Now I have heard of at least 12, including this one, in various stages of
  789. development.
  790.  
  791. 1: This one.
  792.  
  793. 2: The public domain K.G.B. emulator advertised in "Amiga Format".  I have
  794. seen only version 1.2 which does not multitask and does not work properly on
  795. my A3000.
  796.  
  797. 3: An Italian emulator was released (possibly commercially) about 3 years ago.
  798. The version I saw was very bug free and worked on accelerated amigas, but it
  799. did not multitask and was slightly slower than mine.
  800.  
  801. 4: An emulator is under development in Sweden.
  802.  
  803. 5: Another emulator, intended to be commercial, was written in Holland, but it
  804. was never released as far as I know.  From what I have heard about it, it is
  805. much faster than mine.
  806.  
  807. 6: The Whitby Software Spectrum Simulator is a Spectrum ROM rewrite for the
  808. C64.  It runs just fine under TheA64Package and is surprisingly fast.  Because
  809. it is a ROM rewrite and not a z80 emulator, you cannot run z80 machine code
  810. programs (i.e, most games).
  811.  
  812. 7: VGASPEC is a Spectrum emulator for the IBM-PC and clones (not for the
  813. amiga).  A VGA graphics adaptor is required.  I think it was developed in
  814. Spain or Portugal (I don't recognise the language that all the messages are
  815. written in).
  816.  
  817. 8: JPP is another Spectrum emulator for the IBM-PC and clones, developed
  818. recently by Arnt Gulbrandsen.  An 80386 and VGA are required.  It is faster
  819. than VGASPEC.  The name JPP is derived from the keys you press to get LOAD "".
  820.  
  821. 9: There is another very good Spectrum emulator for the IBM-PC.  From memory
  822. I think it is called Z80.
  823.  
  824. 10: There is a Spectrum emulator for the Atari ST available from various ftp
  825. sites.
  826.  
  827. 11: I heard from one person working on a Spectrum emulator for the BBC RISC
  828. computer (status unknown).
  829.  
  830. 12: I have heard rumours of other emulators in various stages of development
  831. in Australia and Germany for platforms including the Amiga, the IBM-PC and
  832. Unix/X-Windows.
  833.  
  834. There is a good collection of Spectrum emulators available by ftp from
  835. wuarchive.wustl.edu and its mirrors.  Programs to convert between various
  836. snapshot formats are also available there.
  837.  
  838.  
  839. Appendix 4:   Update Notes:
  840.  
  841.  
  842. v0.0    22 Oct 1990
  843.  
  844. First release.
  845.  
  846.  
  847. v0.1    15 Nov 1990
  848.  
  849. Sped up display code slightly.  Also sped up main instruction decode slightly.
  850. Display flash attribute as reverse.
  851.  
  852.  
  853. v0.2    30 Dec 1990
  854.  
  855. Now use double buffered display and implemented flash attribute properly.
  856. Added error requesters.
  857. Used pc-relative jump tables in z80 emulator --- slightly faster, and much,
  858. much smaller.
  859.  
  860.  
  861. v0.3    20 Jan 1991
  862.  
  863. Changed display routines to update screen periodically instead of after every
  864. z80 instruction that pokes the Spectrum's display file.  Used the blitter for
  865. this, running in parallel with the z80 emulator.  (Only character rows that
  866. have changed since the last screen update are redrawn.)
  867. Reverted to single buffer display and used blitter to implement flash.  (It's
  868. smaller and faster this way.)
  869. Fixed bug where couldn't use path string in arp file requester.
  870.  
  871.  
  872. v0.4
  873.  
  874. Changed the z80 emulator to use threaded code.  Now all that is executed between
  875. each pair of z80 instructions is "move.w (a3)+,d6; jmp table(pc,d6.w)" instead
  876. of about ten 68000 instructions to decode the next z80 opcode byte.  Overheads
  877. introduced are a new 128 kbyte table giving the routine offset for every byte
  878. in z80 ram, and the necessity to write a zero word into this table every time
  879. the emulator writes to z80 ram.  The overall speed increase is about 20%.
  880. Expanded some subroutines to macros and expanded $dd and $fd prefix
  881. instructions to independent code for a slight speed increase.  A side-effect
  882. is that the executable increased in size from 27k to over 40k.
  883. Introduced some bugs during the systematic changes that are proving hard to
  884. track down.
  885.  
  886.  
  887. v0.5     7 Apr 1991
  888.  
  889. Fixed bug in "sra a" instruction.
  890. Fixed bugs in rotate and shift (ix+d) and (iy+d) instructions.
  891. Fixed bugs where used "offset(a4,rr.w)" to address z80 memory space where offset
  892. is -2, -1, 1 or 2.  (Can't use that mode because of the unlikely event of rr.w
  893. being near $8000.)
  894. Implemented mode 2 interrupts.  Low byte of interrupt vector (normally
  895. provided by an external peripheral device) is assumed to be 0.
  896. Increased the interrupt interval from 2500 instructions to every 5000
  897. instructions, because otherwise some programs with their own (mode 2)
  898. interrupt routines overflowed the stack.
  899.  
  900.  
  901. v0.6    23 Apr 1991
  902.  
  903. Fixed bugs in the following z80 instructions:
  904.     ld     ixh,b
  905.     ld    ixh,d
  906.     rl    (ix+dd)
  907.     rr    (ix+dd)
  908.     sla    (ix+dd)
  909.     cpdr
  910. and iy equivalents of the above instructions.
  911. Implemented ini, outi, ind, outd, inir, otir, indr, otdr.  (Out instructions do
  912.     nothing).
  913. Now preserve (otherwise) unused flag bits in push af, pop af and ex af,af'
  914.     (instead of setting them all to 0).
  915. Changed layout of vector table for threaded code (origin now in middle).
  916. Fixed bug in vector table wraparound code (when pc incremented from 32767 to
  917.     32768).
  918. Sped up ram writes by optimising macro for writing a byte to ram.
  919. Added processor type check.  Now you get a requester when you try to run the
  920.     wrong version for your processor type, instead of "Software Error,
  921.     Task Held".
  922. Implemented sound by opening audio.device and trapping calls to the "beeper"
  923. subroutine at $03b5 in Spectrum ROM.
  924.  
  925.  
  926. v0.7
  927.  
  928. Optimised blits to update flash attributes by keeping track of which parts of
  929. the display are flashing and updating only those parts.  That saves a lot of
  930. blits.  No blits are needed at all when there are no flashing characters
  931. displayed.  It used to redraw the entire display for every blink.
  932.  
  933.  
  934. v0.8    13 May 1991
  935.  
  936. Further optimised the display routines by adding a 6144-byte lookup table.
  937.  
  938.  
  939. v0.9    22 Jul 1991
  940.  
  941. Lower task priority to -5 at startup.  This is friendlier to other tasks
  942. because Spectrum is highly CPU intensive.  If Spectrum is running at a higher
  943. priority than another task, then that other task is completely blocked.
  944. Sped up the emulator by 5% by checking for interrupts only after branch, jump,
  945. call and return instructions, instead of after all instructions.
  946. Open gameport.device and emulate Kempston joystick (at Z80 "in" instruction
  947. level) using the rear Amiga gameport.
  948.  
  949.  
  950. v0.9b    1 Sep 1991
  951.  
  952. Implemented all the undocumented z80 sls instructions.
  953. Fixed bug in ld (nn),sp instruction.  (It didn't work at all!)
  954. Implemented the z80 n flag --- all instructions now set/reset the n flag.
  955. Fixed bugs in inc/dec (hl), inc/dec (ix+dd) & inc/dec (iy+dd) (never set v).
  956. The daa instruction now works correctly after add and sub (not just adc & sbc).
  957. Incorporated Kristian Nielson's tape load routine.
  958. Allocate/free misc.resource.
  959. Added "File already exists! Overwrite?" requester (in save snapshot).
  960. Fixed keypad 0 key.
  961. Rationalised keyboard.  Arrow keys are now equivalent to SHIFT+5/6/7/8 instead
  962. of 5/6/7/8 (without the SHIFT).
  963. ESC key quits.
  964. The halt instruction now calls WaitTOF().  (Was too fast.)  The Spectrum Basic
  965. PAUSE function now works correctly.
  966. Added a separate timer task to prevent interrupts occurring too quickly.  The
  967. "flash" rate and keyboard interrupt rates are now more constant.
  968. The HELP key now displays Spectrum.help IFF/ILBM file from current directory.
  969. Reorganised register usage in z80 emulator to try to speed it up (lots of work
  970. but not much success).
  971.  
  972.  
  973. v1.0    9 Nov 1991
  974.  
  975. Implemented menus.
  976. Added noise correction code to cassette tape loader.
  977. Added support for 2 kinds of sound samplers.
  978. Screen to front after error requester in IFF loader.
  979. Use an interrupt server instead of extra task for timer.
  980. Further optimised blitter routines.
  981. Put z80 parity byte in a register (slight speedup).
  982. Implemented ld-bytes and sa-bytes to/from disk.
  983.  
  984.  
  985. v1.1    Dec 1991
  986.  
  987. Created 68020 version (uses 68020/30/40-only addressing modes for extra speed)
  988. Moved z80 address space to FAST RAM with a copy of 16384..22527 in CHIP RAM
  989. (instead of having the whole Z80 address space in CHIP RAM).
  990. Added more undocumented z80 instructions.
  991. Sped up display routines by changing update algorithm.  Animated graphics and
  992. scrolling are now faster by a factor of 2 or 3.
  993.  
  994.  
  995. v1.2    7 Jan 1992
  996.  
  997. Rewrote joystick handling routines to avoid continuous polling.
  998.  
  999.  
  1000. v1.3    Feb 1992
  1001.  
  1002. Implemented a much faster algorithm for handling z80 prefix instructions that
  1003. was suggested to me by Richard Carlsson.
  1004. Preserve high bit of R register between LD R,A and LD A,R, and also in snapshot
  1005. files.  Tomahawk works now.
  1006. GetCC() is now documented to preserve d0/d1/a0/a1.  Fixed movesr macro.
  1007. Mode 2 interrupts assume $ff is on the external bus, not $00.  This change
  1008. fixed quite a few games.
  1009. Fixed glaring bug in "set 4,l" instruction.  Sabre Wulf, Fighter Pilot, Basil
  1010. the Detective, Athena and lots of other programs work now.
  1011. Changed implementation of daa instruction to speed up add/adc/sub/sbc instrs.
  1012. Use blitter to do comparisons as well as copies in display updater.
  1013. Sped up CPU computation of blitter attribute masks in display updater.
  1014. Display updater now translates black to bright black on the fly.  This leaves a
  1015. colour register free for the border colour (one day).
  1016. Fixed bug in display updater that caused flashing to fail sometimes.
  1017.  
  1018.  
  1019. v1.4    17 Mar 1992
  1020.  
  1021. Changed ld-bytes ROM patch entry point from $0556 to $056b to be compatible
  1022. with more programs.
  1023.  
  1024.  
  1025. v1.4a    22 Mar 1992
  1026.  
  1027. Sped up LDIR by calling CopyMem().  This nearly doubled the speed of some
  1028. programs (e.g, ManicMiner and JetsetWilly).
  1029. Increased the interrupt rate and screen refresh rate when executing lots of
  1030. large LDIRs.
  1031.  
  1032.  
  1033. v1.5    27 Dec 1992 (This version later abandoned)
  1034.  
  1035. Major revamp of z80 emulator, as suggested by several correspondents (3 days'
  1036. work).
  1037. Implemented conventional decoding scheme for z80 instructions, and did away
  1038. with threaded code tables and the overhead of updating them on every write.
  1039. 68000 and 68010 versions now use 2-instruction decode (self-modifying) as
  1040. follows:
  1041.     move.b    (a3)+,1$+2-base(a5)    ; get opcode and modify next instr
  1042. 1$:    jmp    $ff00(a5)        ; jump directly to next instruction
  1043. 68020/30/40 version uses a slightly longer macro to avoid self-modifying code.
  1044. Instruction routines are all exactly 256 bytes in size and the total size of
  1045. all 256 routines is 64 kbytes.
  1046. Added about 5 more such 64 kb blocks of code for prefixed instructions.
  1047. Managed to interleave all the 64 kb code blocks so that they effectively
  1048. reduced to a single 64 kb code block (even sharing the same base address
  1049. register but each table having a different byte-offset).
  1050. About 25 instruction routines didn't fit in their allocated space and
  1051. required long jumps to routines elsewhere.
  1052. Several features broke, including ROM write-protection, invisible ROM-hooks
  1053. for load/save/beep, (in fact I did not re-implement ROM hooks, so loading,
  1054. saving and sound did not work at all), daa mechanism, fast prefix mechanism,
  1055. potential to treat common sequences of instructions as a single instruction
  1056. with no overhead, etc.
  1057. Speed was almost exactly the same as v1.4a (which still had the broken features
  1058. intact), and there seemed to be no significant advantages.
  1059.  
  1060.  
  1061. v1.6    25 Jan 1993
  1062.  
  1063. Gave up on conventional decoding and reverted to v1.4a sources.
  1064. Implemented border colour (at last!)  Made window borderless and changed
  1065. colours.
  1066. The old "filler" byte in the snapshot file format now holds the border colour.
  1067. Added "Reset" menu item.
  1068. Changed sa-bytes ROM patch entry point from $04c2 to $04c6 to be compatible
  1069. with more programs.
  1070. The ld-bytes and sa-bytes routines were not always setting the de, ix and flag
  1071. registers on return, causing some tape-copying programs to fail.  Corrected
  1072. the problem.
  1073. File-names longer than 10 characters passed to the SAVE command could crash
  1074. the amiga.  Corrected the problem.
  1075. Added support for Rombo sound sampler (the one that comes with MegaMIX
  1076. Master).  I do not own a Rombo sound sampler and I have been unable to test
  1077. this option.  (I used information provided by a correspondent in Portugal,
  1078. who also informed me that v1.4a did not work with his Rombo sampler.)
  1079. Implemented sound at the z80 port 254, bit 4, level.
  1080. Changed keyboard handling code to precalculate the most common z80 port address
  1081. values whenever a key is pressed or released, instead of doing a full
  1082. calculation every time an "in" instruction is executed.
  1083.