home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / apps / misc / zx_sp207 / specci.doc < prev    next >
Text File  |  1993-10-25  |  91KB  |  1,648 lines

  1.                  #                      @            #
  2.        @@@@@@@@  @  @@@@@@@@  @@@@@@@@  @  @@@@@@@@  @  @@@@@@@@
  3.        @         @  @      @  @         @         @  @  @
  4.        @@@@@@@@  @  @      @  @         @  @@@@@@@@  @  @
  5.               @  @  @      @  @         @  @      @  @  @
  6.        @@@@@@@@  @  @      @  @@@@@@@@  @  @@@@@@@@  @  @      (TM)
  7.   
  8.                            ZX-SPECTRUM EMULATOR V2.07
  9.                            ==========================
  10.   
  11.   1. INTRODUCTION
  12.   
  13.   This  program  emulates  a  SINCLAIR ZX-Spectrum/48 computer, a Z80-machine 
  14.   with  integrated  BASIC-interpreter,  48  KB  ram,  aquipped  with joystick 
  15.   (Kempston,  Interface  2) and optional Interface 1 with up to 8 microdrives 
  16.   (Sinclair-specific  "mass"-storage  devices).  You need an Atari ST with at 
  17.   least  1  MB  ram  (2  are of advantage) and monochrome 640x400 display (ST 
  18.   hi-res)  or  color  320x200 display (ST low-res). A harddisk is not needed, 
  19.   but   recommended.  There  are  two  versions  of  this  program,  one  for 
  20.   68000-machines  (ST,  (Mega-)STE)  and one for 68030-machines (TT, Falcon). 
  21.   Atari-machines with only 8 MHz tend to be a little slow on emulation, so it 
  22.   will  become  somewhat  boring.  Nevertheless  it  is - by tuning with some 
  23.   emulation-switches   -   possible   even  on  this  machines  to  use  some 
  24.   Spectrum-Programs   or   the   BASIC   in   a   way,   that   the   typical 
  25.   "Sinclair"-feeling  comes up. More interesting it gets at ST-models with 16 
  26.   MHz+Cache, on which the term "emulation" is more appropriate. Some Spectrum 
  27.   programs  will  be  running  actually  faster  than  the original with this 
  28.   machines,  namely  all  those  using  a  lot of LDIR/LDDR-instructions. The 
  29.   average  speed is about 60%. On 68030-models a nearly exact-speed emulation 
  30.   is possible.
  31.   
  32.   Version  1.2 of this program is available since mid 1991 - this new version 
  33.   is  extensivley  enhanced  and  has been made more comfortable in usage and 
  34.   accurate  in  emulation.  For  the  ones  already knowing version 1.2 there 
  35.   follows  a  brief  summary  of the improvements since then - all others can 
  36.   continue reading at chapter 2.
  37.   
  38.   New in version 2.0: !!
  39.   
  40.   - Extensive Setup-Options, which allow the configuration - both from the
  41.     desktop as amidst running emulation - of emulation-switches, paths,
  42.     colour-palette etc.
  43.   
  44.   - Emulation is now about 10% faster and more compatible (IM2, keyboard)
  45.   
  46.   - Integrated Z80-monitor/disassembler, can be reached anytime via ESC-key
  47.   
  48.   - Loading and saving of SNA-files (Ram-snapshots), optionally provided
  49.     with all emulation-switches, so each program can be saved and reloaded
  50.     with the most suitable settings for it.
  51.   
  52.   - Emulator Shell-program, many tool-programs, interfacing to own programs,
  53.     intergration of external screen-drivers...
  54.   
  55.   - generate NMI, use external ROM-files, save the screen to disk anytime,...
  56.   
  57.   So:  a  lot  of changes! A more detailed description will be given starting 
  58.   with chapter 4.
  59.   
  60.   
  61.   2. THE HISTORY BEHIND
  62.   
  63.   Once  upon  a  time  the  author  was  on  a visit to London, when making a 
  64.   decision of grave consequece: he bought on of these neat little black boxes 
  65.   newly  available,  beeing labeled with "ZX81" and produced by a firm called 
  66.   "Sinclair  Research".  There had been wondrous tales beeing spread all over 
  67.   the  world about it. Well, the story about the heroic fight with flickering 
  68.   TV-screens  and  the  "rubout" foil-keyplate would be worth an own chapter, 
  69.   but  as our topic is not the "ZX81", straight to the conclusion: the spirit 
  70.   of  programming  had  taken  over  the  poor  author  and  he  was  full of 
  71.   fascination  for  the  magic  machine-language  Z80. As soon as there where 
  72.   rumours  of  a successor-machine, named "ZX SPECTRUM", it became his own in 
  73.   no  time. Fantastic features awaited the author: opulent BASIC-interpreter, 
  74.   16  colours and sound-generation, 48 KB ram and four times the speed of the 
  75.   ZX81!  The  tape-interface  -  in  contrary  to  its  predesessor  - beeing 
  76.   impressingly  realiable  and  fast, removing the burdon of saving his work. 
  77.   And  the  best of all: a real graphic-mode with 256x192 dots resolution for 
  78.   "real-live"  pictures...  The reader will notice: this statements are meant 
  79.   somewhat  ironical  in respect to todays computer-power; but those days the 
  80.   Spectrum was a real manifastation of programming-power for the author. Soon 
  81.   there  was also good development-software (editor, assembler) available, so 
  82.   the exploration into the depths of Z80 machine-language could be continued, 
  83.   resulting in some respectable own applications. In 1985 the Spectrum had to 
  84.   retire  in  favorite of the Atari ST, but the "first love" stayed always in 
  85.   the  authors mind. So it was not a surprise when thoughts of rebirthing the 
  86.   old friend on the new machine came up. The first experiments doing so where 
  87.   somewhat  unsuccessful  in  1987  due to insufficient knowledege of the ST. 
  88.   Later the author grew more and more to an insider of the ST but the idea of 
  89.   the  Spectrum-emulation  had been fallen in oblivion meanwhile. Until there 
  90.   appeared  a  "ZX81"-emulator  for  the  Atari  ST  in  1990  from Christoph 
  91.   Zwerschke!   This  program  proved  that  it  was  possible  to  emulate  a 
  92.   Z80-machine  on  the  plain  ST  and  brought  back  the lost ideas for the 
  93.   Spectrum-emulation.  As  experience  now  also  was present it did not take 
  94.   long,  until  the first moments of success arrived. Then followed the long, 
  95.   stony  way,  which  had  to be overcome on the track of curious-spectacular 
  96.   totalcrashes   and   mysterous   neurotic  behaviour  of  the  ZX-Atari  or 
  97.   Atari-Spectrum.  The  matured  result  was  presented as version 1.2 to the 
  98.   astonished  public.  This  was  in  june  1991  after  nearly  one  year of 
  99.   development.  Meanwhile more than two years have passed giving the author - 
  100.   beeing  inspired by suggestions of users and his own ideas - plenty of time 
  101.   to  lay  hand on the optimization, performance and user-friendliness of the 
  102.   emulator, till the whole thing has become quite a "round" affair.
  103.   
  104.   3. WHAT THE URGENT USER NEEDS TO KNOW
  105.   
  106.   3.1 INSTALLATION
  107.   
  108.   
  109.   In  order  to squeeze as much as possible onto the emulator-disk, all files 
  110.   have  been compressed with STZIP. Therefore an installation-program will do 
  111.   the  whole  job.  All there needs to be done is to start "INSTALL.PRG" from 
  112.   the  disk.  It  will  query  for the required information. If you install a 
  113.   floppy-disk version of the emulator you will need to prepare four formatted 
  114.   disks with 800kB each (10 sectors, double-sided).
  115.   
  116.   After  successfull  installation  you  will  have  the  option to start the 
  117.   emulator-program  immediatly  or  first call the setup-utility to customize 
  118.   the emulator to your personal needs.
  119.   
  120.   
  121.   3.2. PERFORMANCE-OVERVIEW
  122.   
  123.   As  already  mentioned the ZX-Spectrum is mimict fairly complete. Keyboard, 
  124.   Screen-Display     including     border,     cassette-tape-interface    and 
  125.   sound-generation  -  everything  works  as on the original. Also a joystick 
  126.   interface  is  emulated,  so  most Spectrum games will work with a joystick 
  127.   attached  to  the joystick-port of the Atari. There is an option to emulate 
  128.   the  notorious  interface-1 together with these microdrives. The ZX-printer 
  129.   is  NOT emulated, as a compensation it is possible to route RS232-data from 
  130.   the emulated interface-1 to the printer-port of the Atari.
  131.   
  132.   The  emulator  needs  -  in  its  basic  version  -  the  low  or  the high 
  133.   ST-screen-resolution.  In  low  resolution  it  will  display  all Spectrum 
  134.   colors,   in  high  resolution  suitable  "greylevels"  will  be  used,  to 
  135.   distinguish  the colors. Programmers have an option to implement (with some 
  136.   effort) via a built-in software-interface support for any screen-resolution 
  137.   (see appendix).
  138.   
  139.   3.4 USAGE
  140.   
  141.   After  starting  the  emulator-program  you  will  see  the normal Spectrum 
  142.   boot-process  ending  with the message "(c)  1982  Sinclair Research Ltd.". 
  143.   To  this  time  the  Atari  has  mutated completely to the ZX-Spectrum. The 
  144.   "Alternate"-key and the right Shift-key are installed as "Symbol-Shift" and 
  145.   the   "Control"-Key   simulates  "EXTENDED-Mode".  CapsLock  and  the  left 
  146.   Shift-key  work  as  expected. "Backspace" and "Delete" both give Delete on 
  147.   the   Spectrum   (CAPS-SHIFT+"0").   The  BREAK-key-combination  (Abort  of 
  148.   BASIC-Program)  - Caps-Shift+Space - has been put on the F10-key. All other 
  149.   keys  are  mapped  like  the  original  Spectrum-keyboard.  This means fore 
  150.   example that the symbol "@" can be obtained pressing Symbol-Shift+"2" (i.e. 
  151.   Alternate+"2") and not the Atari way. An overview is given in the appendix. 
  152.   For   all   you   "Non-Sinclair-Compatibles":   the  Spectrum  is  using  a 
  153.   keyword-system  for  input  of  commands.  When the cursor is displaying an 
  154.   inverse  "K"  the  next  pressed  key will be interpreted as a keyword. For 
  155.   example  pressing "S" will immediatly print out "SAVE" or pressing "P" will 
  156.   give  "PRINT".  The decision which time to generate keywords and which time 
  157.   to accept normal letters is done by the Spectrum automatically depending on 
  158.   the syntax. If you experience problems using this system, maybe the program 
  159.   "KEYWORS.PRG" can relieve you (see chapter 8).
  160.   
  161.   The following keys on the Atari are used for special emulator functions:
  162.   
  163.   ESC, F5, F6, F7, F8, HELP, UNDO, INSERT, CLR/HOME
  164.   
  165.   
  166.   Except  of F6 and F7 all these keys are principially free configurable i.e. 
  167.   they  can  be  "connected"  to certain programs, which the user could write 
  168.   himself. Some of these external programs are already supplied, so they must 
  169.   only  be attached to the keys in order of personal preference. See chapters 
  170.   7  and  8  for  more. By default i.e when no own assignements are made, the 
  171.   following is set:
  172.   
  173.   ESC ....... calls the integrated Z80-monitor/disassembler
  174.   F5 ........ calls the SNA-support selection-screen (Special Load and Save)
  175.   F8 ........ does nothing
  176.   HELP ...... does nothing (Help screen of version 1.2 has been removed)
  177.   UNDO ...... switches between four sets of emulator-setups
  178.   INSERT .... leads to the alert "DESKTOP|ZX-RESET|CONTINUE"
  179.   CLR/HOME .. does nothing
  180.   
  181.   F6  .......  is  "hard-wired" with a "RESET"-function, working exactly as a 
  182.   reset-switch  on  the real Spectrum. "Alternate" together with F6 generates 
  183.   an NMI (Non Maskable Interrupt), which at least with the standard rom leads 
  184.   to  a  reset  too. "Shift-F6" quits the emulator immediately and returns to 
  185.   the desktop.
  186.   
  187.   F7  .......  is  aquipped  with  a function to disable the sound-emulation, 
  188.   necessary  for  certain  programs  with  nerving  acoustics.  It works as a 
  189.   tri-state-switch toggling between 'normal' emulation, 'Interrupt' and 'off' 
  190.   (see chapter 4.5 and 7).
  191.   
  192.   3.5 LOADING AND SAVING OF PROGRAMS
  193.   
  194.   To load one of the supplied Spectrum-programs just key in: LOAD "" i.e. key 
  195.   "J"  followed  by two times "Symbol-Shift P" (Alternate P). More easily you 
  196.   can  obtain  the  quote  by  using  the  "~"-key  (the  key  right  to  the 
  197.   "Return"-key).   A   file-selector   appears,   displaying   all  available 
  198.   Spectrum-BASIC-programs.  Should  the  list be empty you may start a "scan" 
  199.   for  loadable programs with the "F2"-key. After selecting one item with the 
  200.   cursor-keys pressing "Return" will load it.
  201.   
  202.   If  you  know  the  name of the program you can of course enter LOAD "name" 
  203.   (instead  of  LOAD  "").  To  save  a program you enter SAVE "name" or SAVE 
  204.   "name" CODE adr,len just as on the real Spectrum.
  205.   
  206.   There   is   another   way   too   to  load  programs  into  the  emulator: 
  207.   Snapshot-files.  For  the moment it will suffice to know, that pressing the 
  208.   "F5"-key  will display a list of all loadable SNApshot-files from where you 
  209.   can select one and load it with "Return".
  210.   
  211.   3.6 QUITTING THE EMULATOR
  212.   
  213.   The  emulator  is terminated pressing "Shift-F6". No safety-request will be 
  214.   given.  Depending on the personal configuration there will be other ways to 
  215.   quit   the   emulator.   With  installed  "SPSETUP.PRG"  you  may  use  the 
  216.   "QUIT"-button.  The  default-configuration  will  display an Alert-Box when 
  217.   pressing the "Insert"-key giving the option to return to desktop.
  218.   
  219.   4. THE EMULATION IN DETAIL
  220.   
  221.   4.1 THE CPU EMULATION
  222.   
  223.   The  ZX-Spectrum is built around the Z80A micro-processor, which is clocked 
  224.   with  3.5  MHz and - beeing an 8-bit chip - has an adress space of 64k. The 
  225.   lower  32k  it  has to share with another chip, the so called ULA, which is 
  226.   responsible  for  all  I/O  processing  (mostly  screen-output).  Therefore 
  227.   programs  running  in  this area are noticable slower than in upper memory. 
  228.   Why  I mention this? Because it must be pointed out, that the emulator does 
  229.   NOT  emulate  the  Z80  in respect of speed-behaviour because the emulation 
  230.   even  on  the Atari TT (in average) is at maximum equal to the original, so 
  231.   it  would make no sense (maybe on 68040-machines). Why, I'll try to explain 
  232.   here:  The Z80-processor has very few in common with the 680xx. This starts 
  233.   with  the  reverse  order  16-bit-quantities are stored in memory (Z80: low 
  234.   byte  first, 680xx: low byte on higher adress), followed by the restriction 
  235.   of  the  680xx to access the high byte of a word directly and ends with the 
  236.   fairly  different  treatment  of  the  status-flags.  All this put together 
  237.   results  in  quite  an  effort  to  simulate a single Z80-instruction using 
  238.   680xx-instructions. Therefore it was necessary to make some simplifications 
  239.   to  yield  an  acceptable emulation-speed. The emulator does not care about 
  240.   the  N-  and  the  H-flag  (Half-carry)  of  the  Z80. As a consequence the 
  241.   instruction  DAA  (a  special  instruction  of  the  Z80  for  addition and 
  242.   subtraction  of  BCD-numbers)  does not work correctly. In the Spectrum rom 
  243.   this instruction is used only once and the emulator takes care that in this 
  244.   one  case  it  works,  but  it is not possible to guarrantee this for other 
  245.   programs  -  in  about  50%  of  the cases it will work, the other will for 
  246.   example  result  in  "mad"  counters, that do not run continiously but jump 
  247.   around  up  and down all the time or other effects.- Also the R-register of 
  248.   the  Z80 is not emulated exactly because each instruction would have needed 
  249.   an additional "add", slowing down the emulator unnecessarily. In most cases 
  250.   the  way the R-registers is simulated is completely sufficient. Last of all 
  251.   the parity-function of the P/V-flag is not emulated by similar reasons. But 
  252.   just  a  few programs use this flag (mostly copy-protection-mechanisms), so 
  253.   this is not really a worry.
  254.   
  255.   But  now to the more pleasant things: all the Z80 opcodes are emulated even 
  256.   the  "inofficial"  ones  using  the  halfs  of  the index-registers and the 
  257.   SLL-instructions.  As  far  as  own  experiments  have shown, also some the 
  258.   ED-instructions  declared as unused yield results given by already existing 
  259.   ED-instructions. For example ED54 does the same as 'neg' (ED44) or ED55 the 
  260.   same  as 'retn' (ED45). The emulator treats them this way but I think there 
  261.   is  hardly  one program using this behaviour of the Z80. The flag registers 
  262.   C,  S,  Z  and V are emulated exactly for all instructions, also the unused 
  263.   bits of the flag-register (bits 3 and 5) are carried with.
  264.   
  265.   Simulation of the Z80 Interrupt-Mechanism
  266.   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  267.   
  268.   50 times a second the emulation-code (so to say the 'microcode' of the Z80) 
  269.   is  interrupted and the emulated IFF (Interrupt-Flip-Flop) is tested to see 
  270.   if  interrupts  are  enabled.  If  no,  there is nothing to do, but if, the 
  271.   processing  has  to  be  stopped AFTER completion of the currently emulated 
  272.   instruction in order to branch into the Z80-interrupt-routine. Therefore an 
  273.   ILLEGAL-instruction  of  the 680xx is put at the end of the 'microcode' and 
  274.   processing  continued normally. When the ILLEGAL is encountered at last the 
  275.   680xx  will generate an exception and jump to a routine, where the emulated 
  276.   Z80  program-counter  is  put on the Z80-stack and changed to the adress of 
  277.   the  Z80-interrupt-routine (with regard to active interrupt-mode). Then the 
  278.   ILLEGAL  is  removed from the 'microcode' and the 680xx continues emulating 
  279.   the   Z80.  This  process  guarrentees  an  exact  simulation  of  the  Z80 
  280.   interrupt-behaviour  and  also  -  beeing (680xx-)interrupt-driven - looses 
  281.   only very little of the precious processor-time.
  282.   
  283.   4.2 THE VIDEO-EMULATION
  284.   
  285.   Whilst  on  the  Spectrum the video-display is completely the job of an own 
  286.   ULA-chip  (ULA  = Uncommited-Logic-Array) i.e. the Z80 only needs to supply 
  287.   the  video-ram  with the picture data, the emulator in addition has to take 
  288.   care  that  these data get onto the Atari screen. Thats not too easy due to 
  289.   the odd way the Spectrums video-ram is organized - much transformation work 
  290.   has  to  be  done.  Especially  this  part  of  the  emulation  needed much 
  291.   fine-tuning  and  optimization in order to make the emulator usable. In the 
  292.   beginning  I implemented the whole thing in the most straigthforward way: a 
  293.   VBL-task   periodically  refreshed  the  Atari-Screen  from  the  Spectrums 
  294.   screen-data. Because this is a very time-consuming work I could not display 
  295.   a  complete  Spectrum-screen  in a single VBL-interrupt, so only some lines 
  296.   could  be  drawn in each interrupt. Although totally optimized, drawing was 
  297.   only  done  when changes occurred, I never was satisfied with the results - 
  298.   it  needed  too long and the drawing "in portions" was notable quite badly. 
  299.   Also the 680xx spent most of its time working out if "something changed" in 
  300.   the  Spectrums  video-ram.  So  I decided to tackle the thing the other way 
  301.   round:  the emulated Z80 already knows exactly when it writes a byte to the 
  302.   screen,  so  the emulator could display it immediatly too! This meant, that 
  303.   all  opcodes of the Z80 that could write to ram had to be "trapped" for the 
  304.   case the target is the ZX video-ram. Then a special routine is activated at 
  305.   once  to  reflect  the changes in Atari video-ram. Due to the fact that one 
  306.   byte  change in ZX video-ram makes necessary up to 32 bytes change in Atari 
  307.   video-ram (with about 300 680xx-instructions) I included a test, if the new 
  308.   value  is  different  to  the  one already in memory (for example: when the 
  309.   screen  is cleared via CLS about 70% of it is already clear in most cases). 
  310.   This  method  worked  outstandingly  well  and  was  also  free  from these 
  311.   "portions"-effects.   The   problem   was   only  to  "trap"  all  possible 
  312.   Z80-instructions.  Some  of  these  you  never  would expect to be used for 
  313.   writing  into  the  video-ram,  like  the  PUSH-instructions (stack-pointer 
  314.   within  video-ram)  or instructions setting bits or even CALL-instructions, 
  315.   that  also  perform  an  internal PUSH. Because I again didn't want to slow 
  316.   down  the  emulator  unnecessarily I didn't trap all those opcodes that are 
  317.   (miss-)used  maybe by 0.5% of all programs to make screen-displays (maybe a 
  318.   68040-version  could  to this, should Atari ever bring out such a machine.- 
  319.   Would  this  not  be  an  incentive,  Atari?). The compromise was, that the 
  320.   common  instructions are "trapped", the others left alone. So it may happen 
  321.   one  or  the other time, that the displays of a program doesn't get visible 
  322.   on  the  Atari.  Just  press  UNDO  a few times, this will redraw the whole 
  323.   screen.
  324.   
  325.   The  Spectrum  knows eight colours: black, blue, red, magenta, green, cyan, 
  326.   yellow  and white each in two intensities (but "black" is "black" no matter 
  327.   what  intensity)  or  brightlevels.  Additionally  there  exists "blinking" 
  328.   (flashing) that periodically toggles background and foreground colour of an 
  329.   8x8-Square  on  the  screen.  These  attributes are exactly emulated. As an 
  330.   additional  luxury  there  is  the possibility to define the colour-palette 
  331.   with  the  setup-program  yourself.  On  the  monochrome screen colours are 
  332.   substituted  by  gray-patterns  (2x2-grid),  which give a suitable display. 
  333.   Emulation  of  "flashing"  and  the display of the colours (leaving black & 
  334.   white  only) can be turned off also, which is only of interest to gain some 
  335.   speed on slow  machines (see chapter 7).
  336.   
  337.   4.2.1 BORDER
  338.   
  339.   The  "border"  is  the  region  around  the display, that can be changed in 
  340.   colour   by   programs.   It   is  emulated  low-level  i.e.  watching  the 
  341.   OUT-instruction  of  the Z80, which makes the emulation principially exact. 
  342.   The big difference to the original is, that a border-change takes "no time" 
  343.   on  the  Spectrum  because  the  ULA-chip  displays  it  while building the 
  344.   picture.  The  emulator  though has to change quite a lot of screen-bytes - 
  345.   for  this  time  emulation  of the Z80 naturally is suspended. Normally you 
  346.   will  not  notice  this,  but  some  programs  use  fast  toggling  of  the 
  347.   border-colour to generate some "fun"-effects (stripes or even "pictures" in 
  348.   the  border-region)  and  the emulator then will busily draw the border for 
  349.   half  a  minute. In order to cope with such situations, the method, how the 
  350.   border  is  drawn  can  be  configured:  either  with  each OUT-instruction 
  351.   immediatly   (which   may   lead   to   the   just  mentioned  problem)  or 
  352.   interrupt-driven  i.e.  the  emulator  updates  the border perodically each 
  353.   1/10th to 1/2 second or the border-emulation can be turned off completely.
  354.   
  355.   4.3 THE KEYBOARD-EMULATION
  356.   
  357.   The  keyboard is emulated (basically spoken) using a table for each keycode 
  358.   of  the  Atari  keyboard,  that  tells  which  bits  to set or clear in the 
  359.   simulated   I/O-portadresses.   The   decoding   is   then   left   to  the 
  360.   keyboard-routine  of the emulated Spectrum. There is one problem imposed by 
  361.   the  Atari's  keyboard-processor:  it  seems to be programmed not to accept 
  362.   more  than  two  keys  pressed  simultanously,  except  for  the Shift-Keys 
  363.   (Control,  Alternate,  Caps-Shift)  and ESC and TAB. This means it will for 
  364.   example  not  notify  the 680xx when an additional key is pressed after "A" 
  365.   and "S" are already pressed. So the emulator cannot notice that too, whilst 
  366.   on  the  Spectrum  it  is  no  problem  to  test, if three or more keys are 
  367.   pressed.  Try  for example 10 PRINT AT 1,1;IN 65022;"  ";:GOTO 10. Pressing 
  368.   more  than  two  keys  in the row "A" to "G" will not change the output any 
  369.   more.  But  nevertheless  this  is  not  a  big problem at all - hardly any 
  370.   program operates on that.
  371.   
  372.   4.4 JOYSTICK-EMULATION
  373.   
  374.   The  emulator  has  four  joystick-emulations  built  in: Kempston-Joystick 
  375.   (using  IN 31), the two Interface-2 joysticks (which simulate keypresses of 
  376.   "1"  to  "5"  and  "6" to "0" resp.) and Cursor joystick. Which joystick is 
  377.   emulated  can  be  selected  in  the setup-program (Emulating more than one 
  378.   joystick  to  the  same  time  has been dropped cause of problems with some 
  379.   programs, which get confused). When asked for the joystick-type in programs 
  380.   you  should  use  KEMPSTON  or  Sinclair  (Interface-2) type. Some very old 
  381.   programs  will  often support only the Cursor-keys, so you could use Cursor 
  382.   joystick in this case.
  383.   
  384.   4.5 SOUND-EMULATION
  385.   
  386.   Sound  is  generated  on  the  Spectrum  by  aid of a buzzer, which through 
  387.   rapidly  turning on and off again is made to "sound" the desired frequency. 
  388.   The emulator does quite the same, but using the poor Atari soundchip (which 
  389.   really  deserves  better)  volume  on  to maximum and off again. But as the 
  390.   emulator is not running at the correct speed the tone will most often sound 
  391.   too  deep.  It will fit better the more the emulator runs at 100% speed (on 
  392.   the TT). Using the function-key F7 you change between this modes:
  393.   
  394.                     - Each OUT will go to the Atari soundchip
  395.                     - Interruptdriven polling of the sound
  396.                     - Turn off sound-emulation completly
  397.   
  398.   The  interruptdriven method gives more constant, but less good results. But 
  399.   using  it  with  a  high scan-rate will slow down the emultor (which may be 
  400.   used as "brake" on very mast machines -  but which??).
  401.   
  402.   4.6 TAPE-SUPPORT-EMULATION
  403.   
  404.   The  old  Speccy  was  able  to  load  or  save  its  programs from or to a 
  405.   cassette-recorder  onto  standard  music-tapes.  The emulator supports this 
  406.   operations  but  automatically directs the data to floppy or harddisk. Some 
  407.   differences  arise  thereout:  Filenames  on the Spectrum may have up to 10 
  408.   characters  wheras  TOS  uses 8 charactes plus 3 characters "extension". So 
  409.   its best to restrict yourself to 8 characters for Spectrum filenames or use 
  410.   filenames  with  a  period  which  in total are not more than 10 characters 
  411.   long. Also loading of the "next" file that comes on tape, using LOAD "", is 
  412.   certainly  not  possible  for  disks.  In  this case a special fileselector 
  413.   appears and the required file can be selected. This fileselector also shows 
  414.   information about the files, namely filesize (as seen for the Spectrum) and 
  415.   startadress  (either in memory or startline of a BASIC-program) - something 
  416.   the author always missed on the Spectrum.
  417.   
  418.   So always when executing a LOAD "" this fileselector will be shown. It is a 
  419.   plain  VT52-application,  no  GEM, having the advantage of ease of use. Use 
  420.   the  cursor  keys  and "Enter" to select a file. There are seperate screens 
  421.   for  each filetype of the Spectrum (Program, Code, Number arrays, Character 
  422.   arrays). So for example LOAD "" CODE will bring up the one for Code.
  423.   
  424.   The information is kept in a file "INHALT.INF" in the current directory. If 
  425.   no  such  file  is  found, a "scan" for loadable Spectrum-Files will start, 
  426.   which  may  take  some  time  because  each  file  in the directory must be 
  427.   examined.  But  normally  you  will not alter files too often. To start the 
  428.   "scan"  manually  you  can  press  "F2".  If  using floppy-disks remove the 
  429.   write-protection-tab,  as  the file "INHALT.INF" is created. As there is an 
  430.   "INHALT.INF"  for  each directory you are in, changing to another directory 
  431.   will bring up the need to read the corresponding "INHALT.INF". This is done 
  432.   with "F1" after changing the path in the upper screenline.
  433.   
  434.   Using the tape-interface out of machinecode-programs will in most cases not 
  435.   enable the emulator to find out the filename wanted. So it tries to present 
  436.   all  corresponding  files  (from the list), hoping that sooner or later the 
  437.   correct  one  is  reached.  You may interrupt pressing the "Alternate"-key, 
  438.   which will bring up the fileselector.
  439.   
  440.   Saving out of machincode-programs will normally not work.
  441.   
  442.   Pressing  BREAK  (key  F10)  during  Load-  or  Save-operations is possible 
  443.   anytime as long as the application does not intercept this.
  444.   
  445.   FORMAT OF FILES
  446.   
  447.   The  emulator  builds  its  files  exactly like the Spectrum does, first 17 
  448.   bytes  header,  then  data.  Header  and  data  are  kept  in a single file 
  449.   together.  The  header  starts  from the begin of the file and has the same 
  450.   layout as the tape-header:
  451.   
  452.        Byte 0  Typ of file: 0=BASIC, 1=Num.Array, 2=Char.Array, 3=Bytes
  453.        Byte 1 - Byte 10 hold program-name, padded with blanks
  454.        Byte 11 and Byte 12: Number of bytes in datablock (lo-hi)
  455.        Byte 13 and Byte 14: Load-adress in memory or starting line in BASIC
  456.        Byte 15 and Byte 16: BASIC only: Program-length minus Variables-length
  457.   
  458.   The program name matches the one you enter with the LOAD-command. The whole 
  459.   file will be created with this name as TOS-file. But remember that Spectrum 
  460.   filenames  are  case-sensitive i.e. SAVE "NAME" and SAVE "name" will create 
  461.   the  same  TOS-file,  but  you will still have to enter LOAD "NAME" or LOAD 
  462.   "name" to laod it!
  463.   
  464.   4.7 INTERFACE-1 EMULATION
  465.   
  466.   The  "Interface-1"  is  an addition-board from Sinclair, which adds a RS232 
  467.   serial-interface  and  a  network-interface to the Spectrum and also allows 
  468.   the  connection of "Microdrives" as mass-storage-device (I will not comment 
  469.   them, because who doesn't know already, needs not know nowadays...).
  470.   
  471.   The network-interface is NOT emulated.
  472.   
  473.   The  RS32-interface is supported, so you can receive files from an original 
  474.   Spectrum  or  send  files to it. Also you could use it to send a listing of 
  475.   ZX-BASIC  to  a printer attached the the Atari. In the setup you can decide 
  476.   where  the  output  will go: Atari RS232- and/or Atari Centronics-port. The 
  477.   BREAK-key can be used as normally to cancel the output.
  478.   
  479.   When  receiving  data  always  the  serial port is used. RS232-settings are 
  480.   taken from the system i.e. the emulator doesn't change any RS232-parameters 
  481.   even  when  using  the  command FORMAT #"b";baudrate. I have received files 
  482.   from my Spectrum at 9600 baud without any problems, but the other direction 
  483.   did  not  work  as  well.  I  could not determine the exact reason for this 
  484.   (mainly  because I have no real need to transfer data TO the Spectrum), but 
  485.   it  seems  that  it  is  rather  due to the cable-connections I use or lies 
  486.   within the Atari handling of the serial port. Anyhow the emulator uses only 
  487.   BIOS  for  operating  the  serial port and no own routines at all, so there 
  488.   will certainly be a way to make it work if you experiment a little.
  489.   
  490.   It  must be noted, that emulation speed is notably slower when "activating" 
  491.   the  Interface-1,  because additional trap-code has to be executed and also 
  492.   the  ROM-paging  be performed (by copying 8192 bytes around in memory often 
  493.   several  times  in a single BASIC-instruction). You should use it only when 
  494.   really neccessary and turn it off otherwise.
  495.   
  496.   4.8 MICRODRIVE EMULATION
  497.   
  498.   These  cute  little things are also emulated, but only for compatability to 
  499.   some  existing  programs,  because it will not make too much sense to store 
  500.   own  programs on it - emulator tapefiles are faster! The emulation is (like 
  501.   the   RS232-emulation)   based  not  on  I/O-level,  but  on  trapping  the 
  502.   program-counter at certain rom-adresses. This means that programs using the 
  503.   official  ways  of  access  (either  from  BASIC  or  through the so called 
  504.   "hook"-codes)  will  work,  but  others  that  try  to  read  or  write the 
  505.   interface-1  ports  will fail. But even in this case you could try to patch 
  506.   the offending code (for example: Art Studio has an incompatible routine for 
  507.   looking  if  a  cartridge  is  present  and will not load its overlay-files 
  508.   because  it  always  reads  a  "not  present"  -dummying this routine makes 
  509.   everything work immedeatly) using the built-in Z80-monitor. Microdrives are 
  510.   implemented  simply  as  files  that  are  structured  like  a  microdrive- 
  511.   cartridge. The names of these files (up to eight microdrives are supported) 
  512.   can  be  defined with the setup-program, numbers "1" to "8" are appended by 
  513.   the emulator automatically. If you really use microdrives with the emulator 
  514.   you  will probably need to be able to change cartridges in a one drive. You 
  515.   could  write  yourself  some  program  that  allows to rename or copy these 
  516.   microdrive-files in an intellegible way and integrate it into the emulator. 
  517.   See  chapter  8  if you want to know more about that. So - whoever wants to 
  518.   experience  the  feeling  of  satisfaction  when the syntax-checker accepts 
  519.   commands like LOAD *"m";1;"name" should do the following:
  520.   
  521.    - Call up the setup-program and click the "MORE OPTIONS" button. Set the
  522.      microdrive-path and filename for a microdrive in the field "MD-Path".
  523.      Then click the button "CREATE.." and select the drives you want to use.
  524.      The files will be created and (if wished) be "formatted" at the same
  525.      time.
  526.   
  527.    - In the first setup-dialog mark the switch "IF1". Save settings.
  528.   
  529.    - Start the emulator. You should see the message "IF1 active!" for a short
  530.      time in the top left corner. - You are now ready to use all microdrive-
  531.      commands, as there are:
  532.   
  533.      FORMAT ( z.B. FORMAT "m";1;"cartr_1" )
  534.      CAT    ( z.B. CAT 1)
  535.      SAVE   ( z.B. SAVE *"m";1;"program" LINE 1 )
  536.      LOAD   ( z.B. LOAD *"m";1;"program" )
  537.      ERASE  ( z.B. ERASE "m";1;"program" )
  538.      OPEN   ( z.B. OPEN #4;"m";1;"seqfile" )
  539.      CLOSE  ( z.B. CLOSE #4 )
  540.      INPUT  ( z.B. INPUT #4;name$ )
  541.      PRINT  ( z.B. PRINT #4;name$ )
  542.   
  543.   
  544.   4.9 SUMMARY OF EMULATION RESTRICTIONS
  545.   
  546.   Let me finally give a short summary of all the above noted restrictions and 
  547.   minor deviations from perfect emulation.
  548.   
  549.    - The Z80 status-flags Half-Carry (H) and Subtraction (N) not emulated
  550.    - R-register isn't implemented exactly, only basically
  551.    - Screen-emulation does not trap all opcodes possible
  552.    - Keyboard cannot be emulated exactly because of Atari firmware
  553.    - Interface-1 is emulted not on hardware-level, only functionally
  554.    - Timing and speed-behaviour (relative and absolute) not cared for
  555.    - Undocumented behaviour of the "unused" flags is not emulated
  556.    - Unused ports are not implemented correctly
  557.   
  558.   5. SNAPSHOT-SUPPORT
  559.   
  560.   5.1. THE STANDARD SNAPSHOT
  561.   
  562.   Well,  it's time to confess: there are other Spectrum-emulators too. One of 
  563.   the first was written for the Commodore Amiga and it used a way for loading 
  564.   and saving Spectrum programs called  SNApshot. It appears that it came from 
  565.   one  of those "freezer" add-on's, which were brought on the market in later 
  566.   years  of  the  Spectrum,  enabling  the  user to break into any program by 
  567.   NMI-interrupt  and  dump the whole ram-contents to disk or microdrive. This 
  568.   was  called  "snapshot",  because  it actually made a snap of the momentary 
  569.   state   of  the  Spectrum  with  all  its  Z80-register,  status-flags  and 
  570.   ram-contents,  so  that  the saved program could afterwards be loaded again 
  571.   and  continued from exactly the point, where it was saved. Another emulator 
  572.   for  the  PC,  called "jpp", also used this format later, so it may be said 
  573.   that  it  is  a  sort of "standard" under Spectrum-emulators (sounds really 
  574.   crazy!). Therefore this emulator also supports snapshots.
  575.   
  576.   THE BUILT-IN SNAPSHOT-SUPPORT SCREEN
  577.   
  578.   In  order  not  to let the emulator grow too large (so that users with 1 Mb 
  579.   only  also  can  use  it), the abilities of the internal user-interface for 
  580.   loading  and  saving snapshots are quite basically. All those with more ram 
  581.   should  use  the  external  program  "ZXF", offering much more comfort (see 
  582.   chapter 8).
  583.   
  584.   But now I will discuss the internal function: Pressing the key "F5" anytime 
  585.   takes  you  to the "SNA-Support"-screen. It allows to input a filename of a 
  586.   snapshot  file,  that  shall  be  loaded  or  saved to. If you enter just a 
  587.   filename  (with  no  path)  the current snapshot-path (as declared with the 
  588.   setup-program) will be used, otherwise the path entered is taken. After the 
  589.   name  has  been  typed you have to press "Return" to load the file or press 
  590.   "F5" again to save the current program in memory to this file.
  591.   
  592.   If  you  enter  no name (leave the field empty) the default-name "temp.sna" 
  593.   will  be  used.  This  has  the advantage, that you can very quickly save a 
  594.   current  game  (for  example to preserve a completed level) by hitting "F5" 
  595.   twice. To load it back again you just have to press "F5" and "Return".
  596.   
  597.   LOADING SNAPSHOTS FROM THE TAPE-FILESELECTOR
  598.   
  599.   I  built  in a recognition of snapshot files into the tape-selector lately. 
  600.   They  will be shown within the program-type-files and you see them as files 
  601.   with  length  49179 bytes. You can load them,  entering the LOAD "" command 
  602.   just  like a tapefile. As a feature the snapshot will not be run immedeatly 
  603.   but  a  branch  to the internal Z80-monitor is taken after loading, so that 
  604.   you can inspect it or make patches. Just hit "Esc" to run it.
  605.   
  606.   5.2 THE EXTENDED SNAPSHOT-FORMAT
  607.   
  608.   I  used  the  opportunity  to create an own snapshot-format, which I called 
  609.   "SNX"-format (SNApshot eXtended). It offers the advantage that it can store 
  610.   the  current  emulator-settings  too, so that you can run each program with 
  611.   the  best  choice  of settings right away. Also it does some compression to 
  612.   the  data,  in  contrary  to the standard snapshot, which always uses 49152 
  613.   bytes,  independend  of how large the program really is. It's a very simple 
  614.   method  of  compaction,  but  efficient  with  small  programs and quick to 
  615.   perform. If you want better compression you could  write your own load- and 
  616.   save-programs  by  using  the  emulators ability to "connect" with external 
  617.   programs (see chapter 8).
  618.   
  619.   Snapshots  in  the  "standard"  format  can  be  interchanged  with   other 
  620.   Spectrum-emulators with ease.
  621.   
  622.   5.3 AUTO-STARTING A SNAPSHOT-FILE
  623.   
  624.   At the start of the emulator two things are checked:
  625.   
  626.     If  there  exists  a  snapshot  "AUTO.SNA" (which can also be in extended 
  627.   format,  but the extension has to be ".SNA") it will be executed immedeatly 
  628.   after  the  emulator has been started (or after a reset, if you like). This 
  629.   could   be   used   to   run  a  menu-program  or  some  extension  of  the 
  630.   operating-system   automatically.   The   check  is  done  only,  when  the 
  631.   emulator-switch "AUTO" has been set in the configuration.
  632.   
  633.     If you pass a filename to the emulator by command-line, this file will be 
  634.   interpreted  as  snapshot  and loaded immediatly. This makes it possible to 
  635.   declare  the  emulator  as  application  for snapshot-files to the desktop. 
  636.   Clicking on a snapshot-file will then activate the emulator and execute the 
  637.   Spectrum-program.  So, what about designing an icon for "Jet-Set-Willy" and 
  638.   try it?
  639.   
  640.   5.4 CONVERSION PROGAMS FOR SNAPSHOTS
  641.   
  642.   In  order  to convert easily between the various formats three programs are 
  643.   supplied with this version of the emulator (in the SNA-folder):
  644.   
  645.     SNA2SNX.PRG      Will convert a standard snapshot to the compressed SNX-
  646.                      format of this emulator. If it finds SPECCI.DAT then it
  647.                      will use the current settings of switches contained in
  648.                      it, otherwise it uses default values.
  649.   
  650.     SNX2SNA.PRG      Converts and extended snapshot back to a normal one.
  651.                      The extended information is lost of course.
  652.   
  653.     Z802SNX.PRG      Converts snapshots of one popular Spectrum emulator for
  654.                      MS-DOS PC's into SNX-snapshots for this emulator. It
  655.                      tries to translate as much information as possible from
  656.                      the Z80-settings (joystick emulation, double interrupt
  657.                      frequency, Interface-1 emulation, ...).
  658.   
  659.   All  of this programs can handle the passing of a snapshot filename through 
  660.   the  command  line.  If  non  is  supplied  you  are prompted for a file to 
  661.   convert.
  662.   
  663.   
  664.   6. THE IN-BUILT Z80-MONITOR
  665.   
  666.   One  keypress  away - "Esc" by default - there slumbers a Z80-disassembler/ 
  667.   monitor  waiting  to  be  woken.  It  makes  it fairly easy to sniffle into 
  668.   programs,  search  for byte-sequences and do patches. Its operation is made 
  669.   simple  by  using  a  "hot-keyboard"-technique.  This  means it will not be 
  670.   neccessary  to  press  "Return"  in  most  cases,  but  the  monitor reacts 
  671.   instantly  to  keys. Numbers have to be input in hexadecimal throughout the 
  672.   program,  after  entering  sufficient  digits  the  input  will be accepted 
  673.   automatically. Each command can be aborted by pressing "Esc" as long as its 
  674.   input  is  not  finished.  Numbers  displayed  will also be in Hex with the 
  675.   exception  of  ix/iy-offsets  like 'ld a,(ix+11)', which are in decimal and 
  676.   binary  operations (AND,OR,XOR) which will be in binary (dual) format (i.e. 
  677.   'xor a,%10000000').
  678.   
  679.     Monitor-Commands in Detail:
  680.     ---------------------------
  681.     ESC            during command-input: cancels the command
  682.     ESC            when the '>'-prompt is showing: Quit the monitor WITHOUT
  683.                    setting of any changed registers (see 'X'-command).
  684.     H              Help. Shows a brief summary of commands.
  685.     A adr          Set start-adress for D,L,M,F-commands.
  686.     D              Disassemble from adr
  687.     L              Hexdump-Listing from adr. ZX-Codes are shown righthand.
  688.     SPACE,Return   Continue D or L, one line at each keypress.
  689.     M B            Modify memory from adr byte-wise.
  690.     M W            Modify memory from adr word-wise ($1234 will be stored
  691.                    as $3412 !)
  692.     M A            Modify memory from adr in ascii (text-input).
  693.     M C            Modify memory from adr with a constant value:
  694.                    Pressing <Return> will use the constant, otherwise the
  695.                    input value.
  696.     F B v1 v2 ..   Find a sequence of bytes starting search from adr.
  697.                    After 7 occurences a new line is used a <Return> must be
  698.                    pressed to continue or <ESC> to stop.
  699.     F A text       Find a text-string.
  700.     R              Show Z80-registers.
  701.     X              Change registers.
  702.                    The registers are displayed. Then each register can be
  703.                    changed in turn. Pressing <Return> will leave the current
  704.                    value and advance to the next register. <ESC> leaves the
  705.                    mask if no more registers shall be changed. When entering
  706.                    interrupt-mode only values 0 to 2 are allowed amd for 
  707.                    the status '+' or '-'.
  708.     G <adr>        Go on emulation starting at adr.
  709.                    if adr is not specified, the current PC will be taken.
  710.     U adr          Go until adr.
  711.                    A breakpoint is set at adr and a G-command is executed.
  712.                    When the breakpoint is reached the monitor will show
  713.                    again. Should the program not encounter the breakpoint,
  714.                    it will be cleared automatically when the monitor is
  715.                    entered again.
  716.     I              Single-step one Z80 instruction (current PC).
  717.     N H/D number   Number conversion decimal <-> hexadecimal.
  718.     Z              Show the current ZX-screen. Press 'Z' again to return.
  719.     S <name>       Saves the Zx-screen in Spectrum-format (17 bytes header +
  720.                    6912 bytes screen-data) under 'name'.
  721.                    If 'name' is not specified, the dafault 'zxsc' is used.
  722.                    If the name does not contain a path, saving will go to
  723.                    the current program-path.
  724.                    The saved screen can be laoded then from the emulator 
  725.                    with LOAD "name".
  726.                    The external program 'ZX_BILD.PRG' allows to load
  727.                    ZX-screens and save them in Doodle- or Degas-format (see
  728.                    chapter 8.6).
  729.     V              Reset start-adress of disassembly to PC.
  730.   
  731.   7. PERSONAL CONFIGURATION
  732.   
  733.   Using  the  program  "SPSETUP.PRG"  the  emulator  can be configured to the 
  734.   individual taste. The following settings may be done:
  735.   
  736.   Use other ROM-file
  737.   ==================
  738.   
  739.   The button "ROM" must be activated. The line above contains the path to the 
  740.   ROM-file  that  shall  be  used.  Clicking  on  this line will bring up the 
  741.   fileselector  and  a  ROM-file can be selected. It must be a file of either 
  742.   16384  bytes  (main  rom)  or 16384+8192 bytes (main rom + Interface-1 rom) 
  743.   length.
  744.   
  745.   Define special keys and attach them to programs
  746.   ===============================================
  747.   
  748.   The keys "Escape", "F5", "F8", "Home", "Help" and "Insert" can be routed to 
  749.   perform  own  functions.  This  im  implemented in that way, that any other 
  750.   program  can  be  started  when  pressing on of these keys. As described in 
  751.   chapter 8 there are quite complex ways to interact with the emulator. It is 
  752.   also  possible  to  install  this  external programs resident in memory, so 
  753.   reloading will not be neccessary and one gets the impression of an in-built 
  754.   emulator-function.
  755.   
  756.   After  clicking  on  the button "Config" a dialogue appears, where the keys 
  757.   can  be  attached  to  programs.  The  check-box  on  the  left side of the 
  758.   program-name  activates or de-activates the corresponding program. The name 
  759.   has  to  be  keyed in manually, because a mouse-click on the name will open 
  760.   another box, where some settings for this program can be made:
  761.   
  762.   - Restore Colour-palette before activating the program:
  763.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  764.   
  765.     Description: The system-palette as before the start of the emulator will
  766.                  during emulation be changed to the Spectrum "palette".
  767.                  This option decides whether the saved palette shall be
  768.                  restored before calling the program or if shall use the
  769.                  Spectrum colours.
  770.   
  771.   - Run program in ZX-mode i.e. with active emulator:
  772.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  773.   
  774.     Description: During emulation some system-vectors are changed ore de-
  775.                  activated. Especially the keyboard-routine and the timers
  776.                  B and C are changed. Therefore this option should normally
  777.                  be disabled, but special programs could use it to interact
  778.                  more closely with the emulator.
  779.   
  780.   - Load program resident into memory:
  781.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  782.   
  783.     Description: As already mentioned it is possible to load user-programs
  784.                  resident in memory. Use this switch to do it. Especially
  785.                  for floppy-disk users this may be of advantage. But programs
  786.                  must be designed to work in this mode, for example they must
  787.                  take care if their data (resources) are already initialized.
  788.   
  789.   - Use return-value from program:
  790.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  791.   
  792.     Description: This switch tells the emulator to interpret the return of
  793.                  the program. Programs that supply a return-value must of
  794.                  course do it according to the requirements of the emulator.
  795.                  See appendix for a description.
  796.   
  797.   The check-boxes on the right side are used only for the "Shell-Mode" of the 
  798.   emulator,  which means when it is called from a special Shell-Program. If a 
  799.   box  for  a  key is checked, the emulator will return to the shell-program. 
  800.   All  other settings have no meaning in this mode, but the Shell-Program has 
  801.   to  decide  what  to  do,  when  the emulator returns with key x. One could 
  802.   imagine  the emulator to be only a subroutine to the shell, that by the way 
  803.   emulates  a  ZX-Spectrum computer and returns with defined values. Read the 
  804.   appendix for a more detailed description.
  805.   
  806.   Define four different Sets of configurations
  807.   ============================================
  808.   
  809.   For  easy access of different emulator-settings there are four sets you can 
  810.   define and then switch in runtime with a keypress (default: UNDO). A set is 
  811.   selected  by  clicking at its number in the title. The one currently active 
  812.   is inverted.
  813.   
  814.   Description of the emulator-switches:
  815.   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  816.   
  817.   IF1          Turns on interface-1 emulation. From version 2.07 on it is
  818.                possible to change this switch in runtime.
  819.   ULA          Turns on the screen-emulation in the 50Hz-timesclice. This is
  820.                mainly to reduce flickering of sprites with some games (for
  821.                example Matchpoint).
  822.   FLASH        Turn flash-emulation on. If it is turned off, flash will only
  823.                invert the character. Turn it off, whenever possible, if you
  824.                have a slow machine.
  825.   ATTRIBUTES   Turns on emulation of the attribute-file. Should normally be
  826.                on. If turned off only the pixel-data will be displayed. It
  827.                is sometimes quite intersting to see, how the attributes are
  828.                used to hide things on the screen, that are actually there.
  829.   R-REGISTER   Emulate (Simulate would be more accurate) the R-register. If
  830.                turned off, the value of the R-register is left constant. This
  831.                might be usefull sometimes, because programs then always will
  832.                request the same pass-words if they rely on the changing value
  833.                of the R-register. Turning it off, will gain no speed!
  834.   X-SNA        Turns on saving in extended format (SNX-format). If turned off
  835.                saving will be done in the standard format (SNA-format).
  836.   100 INT/S    Doubles the emulated interrupt-frequency. This often brings a
  837.                much better control of the keyboard, especially on slow ST's.
  838.   CHANGE Z-Y   Who doesn't like, that the Z- and Y-keys (at least on a german
  839.                keyboard) are different as on the Spectrum, can cure it here.
  840.   RS232-OUTPUT Sets where RS232-output from the Interface-1 emulation will go
  841.                to: serial port, parallel port, both or none.
  842.   AUTO-SNA     If set, the emulator will automatically try to load a snapshot
  843.                named "AUTO.SNA" after start and/or an reset.
  844.   SOUND        Set method of sound-emulation (see chapter 4.5). If you set to
  845.                "Interrupt" you can also change the scan-rate by clicking at
  846.                the box named "INTERR.".
  847.   BORDER       Same as SOUND, but for the display of the border.
  848.   Z80-ILLEGAL  Sets the action, the emulator shall take, when encountering an
  849.                illegal Z80-opcode.
  850.   EMU-ERROR    Sets the action, when an emulation-error occurs (680xx adress-
  851.                or bus-error). This should not happen anyway.
  852.   
  853.   Setting the color-palette
  854.   =========================
  855.   
  856.   Under  "MORE  OPTIONS" you can enter your own values for the low-resolution 
  857.   colour-palette, in case you are not satisfied with the given ones. Clicking 
  858.   at  the field "Color palette" a menu with some more or less usefull options 
  859.   assist you in experimenting. It's best to try from the running emulator, so 
  860.   you can see the effects immedeatly when returning to it. In high resolution 
  861.   a click in this field will invert the screen (toggle white/black).
  862.   
  863.   Define paths for Tapefiles, Snapshots and Microdrives
  864.   =====================================================
  865.   
  866.   In  the  same  dialogue  also all filepaths can be selected. You can either 
  867.   type them in or click on the fields and then use the fileselector.
  868.   
  869.   Set some hardware-values of the Spectrum
  870.   ========================================
  871.   
  872.   Also under "MORE OPTIONS" you can set the value that the Spectrum generates 
  873.   for  the  Interrupt-Mode-2  hardware-vector. The default $ff should in most 
  874.   cases be correct, but I made this value user-definable nevertheless.
  875.   
  876.   Different  series  of  Spectrum-issues  had a small incompatabilty with the 
  877.   level  of  Bit  6, the "EAR-bit" or input-value from the tape-interface. As 
  878.   the tape-interface didn't rely on the absolute value "0" or "1" but only on 
  879.   the change of state, this normally made no difference, but when reading the 
  880.   keyboard  also  the  EAR-bit is read and some older programs do not mask it 
  881.   out  when  interpreting the key-value read. If the keyboard doesn't seem to 
  882.   work  with  some  older program, try to change the value for the EAR-bit to 
  883.   "1".
  884.   
  885.   Last  of  all the type of joystick to be emulated can be set. Most Spectrum 
  886.   programs  will have an option for "KEMPSTON"-joystick, which is emulated by 
  887.   default, the others will certainly offer an "Interface-2"-option.
  888.   
  889.   As  all  these  values are stored in SNX-snapshots, you will have to change 
  890.   them only once for each program.
  891.   
  892.   PLEASE NOTE
  893.   ===========
  894.   
  895.   Alle  Settings  in  the  "MORE  OPTIONS"  dialogue are only for the current 
  896.   active  set.  This  has  the  advantage,  that  you  can  also  toggle  the 
  897.   colour-palette  or  the emulator-filepaths with a keypress, but requires on 
  898.   the other hand, that you do this settings for each other set as well.
  899.   
  900.   Other things the program "SPSETUP" can do:
  901.   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  902.   
  903.   The program is "runtime"-able i.e. you can define it as an external program 
  904.   itself,  which  gets  executed  by pressing (for example) "Insert" when the 
  905.   emulator  is  running.  You  must  set  the  following  parameters  in it's 
  906.   configuration-box:
  907.   
  908.   Atari-mode  (i.e.  NOT Spectrum-mode), WITH return-value, the other options 
  909.   as you like.
  910.   
  911.   When  it  is  called  from the emulator it offers some other buttons, which 
  912.   replace  the  ROM-buttons:  Generate  NMI,  Generate  RESET,  Load and Save 
  913.   Snapshots, Screen, any part of the memory and Quit the emulator.
  914.   
  915.   Also  a button "SAVE SETS" in the lower part of the dialogue allows to save 
  916.   the   whole   settings   of  the  emulator  (in  ram)  permanently  to  the 
  917.   emulator-file "SPECCI.DAT". This is usefull when you are experimenting with 
  918.   different settings and want to preserve them at last, when satisfied.
  919.   
  920.   The  title-line  will  show  an  additional  set  "T",  which resembles the 
  921.   work-set, a copy of the current active set. Any changes done in the "T"-set 
  922.   will  have no lasting effect, only till loading an SNX-snapshot or toggling 
  923.   sets  with  the  defined  toggle-key. So it can be used whenever you do not 
  924.   want to corrupt your sets.
  925.   
  926.   8. THE ADD-ON PROGRAMS
  927.   
  928.   8.1 GENERAL REMARKS TO THE INTEGRATION OF EXTERNAL PROGRAMS
  929.   
  930.   Most programs presented here are written in GFA-BASIC, which is my declared 
  931.   favourite-language  besides  assembler. A "quantum-leap" in comfort was the 
  932.   discovery  of how to make programs resident in memory and how to start them 
  933.   from  there  as  often  as  needed.  A  initial  problem  with the compiled 
  934.   GFA-programs   could   be   overcome  using  a  patch-procedure,  which  is 
  935.   incorporated   into   the  program  and  executed  at  the  first  resident 
  936.   activation, so following executions will work.
  937.   
  938.   8.2 KEYWORDS.PRG
  939.   
  940.   Ends  the  pity  with  searching for that dreaded keyword in ZX-BASIC. This 
  941.   program  is  thought  to serve as resident replacement of (for example) the 
  942.   HELP-function.  All  characters  and BASIC-token of the Spectrum are listed 
  943.   and  can  be scrolled through using the cursor-keys. Pressing "Return" will 
  944.   pass  the  character  under the cursor to the emulator (it will actually be 
  945.   patched  into the system variable LAST_K). The "F1"-key toggles the display 
  946.   sorting  alphabetically  or  by  code.  "Esc" leaves without overtaking the 
  947.   character.
  948.   
  949.   Configuration in Setup:
  950.   ~~~~~~~~~~~~~~~~~~~~~~~
  951.   
  952.   Atari-Mode, WITHOUT return-value, resident & palette as you like
  953.   
  954.   You can start the program also from desktop (display only, of course).
  955.   
  956.   8.3 SPSHELL.PRG
  957.   
  958.   Emulator-shell,  which  allows  to  get  all of the add-on-programs under a 
  959.   GEM-menu  and to use the accessories from out of the emulator. It needs the 
  960.   file  "SPSETUP.INF",  that contains the list of programs and parameters for 
  961.   them. See also appendix.
  962.   
  963.   8.4 ZXF.PRG
  964.   
  965.   A replacement for the minimal-art fileselector for snapshots built into the 
  966.   emulator.  Therefore  it  should  be  put onto the key "F5". If you make it 
  967.   resident  too, you will think it is a natural part of the emulator-program. 
  968.   When  called  it  will display all snapshot-files in the current directory. 
  969.   You  will  also  see the other available disk-drives and directories on the 
  970.   current  drive  and  are  allowed to change to them. Using the cursor-keys, 
  971.   Space  or  Tab you can browse through the list and select a file or you can 
  972.   input  a new filename for saving. When entering a filename the display will 
  973.   be  updated  with  each  key, to show all matching files. Pressing "Return" 
  974.   will  load  the snapshot, pressing "F5" will save to it. You do not need to 
  975.   enter  an extension, this will be done automatically. If you want to create 
  976.   a  file without an extension put a period at the end of the filename. There 
  977.   will  be  a  warning  if you try to overwrite an existing file. "HELP" will 
  978.   start  a  "scan"  for  for snapshot-files, that have not been recognised by 
  979.   their extension or filelength. "UNDO" will switch to full-screen display to 
  980.   show  more  files at once. "Insert" copies the name under the cursor to the 
  981.   input-line,  "Clr"  blanks  the input-line. Escape leaves without action to 
  982.   the emulator.
  983.   
  984.   When  started from the desktop ZXF allows to run the emulator automatically 
  985.   with a selected snapshot - a very convenient way to start the emulator.
  986.   
  987.   
  988.   Configuration in Setup:
  989.   ~~~~~~~~~~~~~~~~~~~~~~~
  990.   
  991.   Atari-Mode, WITH return-value, resident & palette as you like.
  992.   
  993.   8.5 ZX_TAST.PRG
  994.   
  995.   A  nice  display  of  the original ZX-keyboard. This version shows a fairly 
  996.   realistic  picture  at  least  in  color-mode, but splitted into four parts 
  997.   there. It's contained in a GEM resource-file, that can be worked on using a 
  998.   resource-editor.
  999.   
  1000.   8.6 ZX_BILD.PRG
  1001.   
  1002.   A  program  to  display ZX-screens (filelength 6912 bytes) in 640x400/2 and 
  1003.   320x200/16.  Clicking  with  the  mouse will bring up a menu that allows to 
  1004.   save  them  in  Degas-  or  Doodle-format.  This  program is not worked out 
  1005.   completly - you could use it as a base for own developments.
  1006.   
  1007.   8.7 ZXH.PRG
  1008.   
  1009.   This is the help-function of version 1.2, now as external program. It shows 
  1010.   the ZX-keyboard - according to the screen-resolution maybe in several parts 
  1011.   that  can be moved through using the "HELP"-key. Any other key will end it. 
  1012.   If  resident  in  memory  and  used  in ZX-mode it will pass the key to the 
  1013.   emulator.
  1014.   
  1015.   Configuration in Setup:
  1016.   ~~~~~~~~~~~~~~~~~~~~~~~
  1017.   
  1018.   resident, Atari or ZX-mode, WITHOUT return, do NOT restore palette.
  1019.   
  1020.   8.8 ZXS.PRG
  1021.   
  1022.   A  program  to  do  the same job as the inbuilt function for toggling sets. 
  1023.   It's  single  purpose  is to free the "UNDO"-key for another function. Then 
  1024.   you  could assign this program to the key you would like to do switching of 
  1025.   sets.
  1026.   
  1027.   Configuration in Setup:
  1028.   ~~~~~~~~~~~~~~~~~~~~~~~
  1029.   
  1030.   resident, Atari-Mode, WITHOUT return-value, do NOT restore palette.
  1031.   
  1032.   8.9 ZXM.PRG, ZXU.PRG
  1033.   
  1034.   This  are sample-programs, to show how (easy) to interact with the emulator 
  1035.   from  external  programs. Of course a profound knowledge of the ZX-Spectrum 
  1036.   will  not  be  a  hindrance.  Then there will be few limits for what can be 
  1037.   done.  "ZXU.GFA" will simulate a LOAD "" input to the emulator, to call the 
  1038.   tape-fileselector  with  a single keypress. It does so, by changing some of 
  1039.   the   Spectrums   system-variables   to   fool   the   Spectrum.  "ZXM.GFA" 
  1040.   demonstrates,  how  to  obtain  the  values of the Z80-registers and how to 
  1041.   change  them  (for  doing  a reset in this case). "ZXU.PRG" will be of some 
  1042.   beneficial  effect,  whilst  "ZXM.PRG"  shall definitly only be an example, 
  1043.   that can be studied.
  1044.   
  1045.     ZXU.PRG: resident, WITHOUT return, Atari-Mode, do NOT restore palette
  1046.   
  1047.     ZXM.PRG: resident, WITHOUT return, Atari-Mode, palette as you like
  1048.   
  1049.   
  1050.   9. THE FINAL FRONTIER
  1051.   
  1052.   This documentation has grown somewhat lenghty, I fear. I only hope, not too 
  1053.   dull  to  read. The appendix will give information to the one interested in 
  1054.   writing  own  stuff around this emulator. There remain just a few points to 
  1055.   mention:
  1056.   
  1057.   - How to get Spectrum-programs over to the emulator ?
  1058.   
  1059.   Well,  beeing  aquipped with a working Spectrum and Interface-1, it will be 
  1060.   an  easy  job  to transfer unprotected programs using a suitable cable. The 
  1061.   format  of  the emulators "Tape"-files is identical to that of the Spectrum 
  1062.   anyway.  Ensure  that the system-parameters for the RS232 interface are set 
  1063.   to  9600  baud,  no  parity,  1 stopbit and RTS/CTS handshake and start the 
  1064.   emulator  with  Interface-1  emulation  turned  on.  Then you could receive 
  1065.   programs  or machine-code from the connected Spectrum by simply typing LOAD 
  1066.   *b;"" or LOAD *b;"" CODE on the emulator and a corresponding SAVE *b;"name" 
  1067.   or  SAVE *b;"name" CODE start,len on the Spectrum. Once in memory save them 
  1068.   to disk in the normal way.
  1069.   
  1070.   Copy-protected  software  will  be hard to transfer for the non-hacker. The 
  1071.   simplest way might be a modified Spectrum-ROM, which could be programmed to 
  1072.   dump  the  whole  ram-contents  to  the Atari when triggering an NMI on the 
  1073.   Spectrum. I personally use this method, so I could give helping information 
  1074.   if someone is interested in.
  1075.   
  1076.   Someone  in  England  has  developed  a  program,  that  can  read original 
  1077.   Spectrum-tapes  from  a  tape-recorder  connected to the Atari by a special 
  1078.   cable on the printer-port. Though I have this program, I didn't try it, but 
  1079.   it  is  claimed  to work well. Of course only on unprotected tapes and only 
  1080.   with 8 MHz Ataris (because of the timing-loops).
  1081.   
  1082.   Another  way  to  get  hold  of  programs  in  snapshot-format  may  be the 
  1083.   "emulator"-section  of various mailboxes. As there are at least three other 
  1084.   Spectrum-emulators   (one   for  Amiga  and  two  for  the  PC)  using  the 
  1085.   snapshot-format, you could load programs for them into this emulator too.
  1086.   
  1087.   Finally  the  author also has about 300 programs you could obtain. Send SAE 
  1088.   for a list if interested.
  1089.   
  1090.   This leads to the next topic:
  1091.   
  1092.   - Queries, Questions and problem-curing:
  1093.   
  1094.   I am willing to answer any questions brought to my ears, BUT ONLY, if there 
  1095.   arise  no  costs  for  me. This emulator is Public-Domain, so I cannot do a 
  1096.   service-job  for  it.  At  least  a  compensation  for postage and disks is 
  1097.   expected.  An  additional  "honouring"  of  time  and  work  needed will be 
  1098.   appreciated.  I  am  also  willing (in principle) to give away the emulator 
  1099.   source-code, but not just for fun, only when beeing convinced that it is in 
  1100.   "good" hands.
  1101.   
  1102.   Of course plain and honest notes of approbation to this program are welcome 
  1103.   in  any circumstance - that's what the author of a Public-Domain program is 
  1104.   always (and only) hoping for (as a return to his laborous work).
  1105.   
  1106.   
  1107.   Last  of  all, some remarks to a topic I would rather like to byepass - the 
  1108.   problematic chapter "copyright":
  1109.   
  1110.   The  emulator  contains a copy of the Spectrum rom and the Interface-1 rom. 
  1111.   Certainly,  it  would have been the easiest way for me, to leave  it to the 
  1112.   user  to  get  hold  of  these  files and patch them into the emulator. But 
  1113.   firstly  it  seemed  unacceptable  to  assume, everybody interested in this 
  1114.   emulator  would have the means and the knowledge to obtain and transfer the 
  1115.   rom-files to the Atari, secondly I do not distribute the rom-files on their 
  1116.   own  and this emulator is not a commercial product also. I think the age of 
  1117.   the  ZX-Spectrum  is  too  long ago, as it could be an real infringement of 
  1118.   copyright, in the contrary: it should be of interest to those in possession 
  1119.   of the copyright for the Spectrum-rom (Armstrad company, I presume) to hold 
  1120.   high the remniscence of the Spectrum. A person starting a Spectrum-emulator 
  1121.   nowadays  must  be really a "nostalgic", and I didn't want to cut down this 
  1122.   romantic feelings early with problems, how to get this or that file.
  1123.   
  1124.   
  1125.                                   So: Have fun and enjoy the emulator!
  1126.   
  1127.   
  1128.                                   Christian Gandler
  1129.                                   Paletzgasse 17/3/14
  1130.                                   1160  Wien / Vienna
  1131.                                   ÖSTERREICH / AUSTRIA
  1132.   
  1133.   
  1134.   
  1135.                                   LONG LIVE SPECCI !  ( & ATARI !)
  1136.   
  1137.   
  1138.                                                              Vienna, 25.10.93
  1139.   
  1140.   ----------------------------------------------------------------------------
  1141.   
  1142.   10. APPENDIX
  1143.   
  1144.   A: SUMMARY OF EMULATOR-KEYS
  1145.   ===========================
  1146.   
  1147.     ST-Key(s)        as pressed on ZX-SPECTRUM     Comment
  1148.     -----------------------------------------------------------------------
  1149.     Control          Caps-Shift+Symbol-Shift       EXTENDED-MODE
  1150.     Alternate,RShift Symbol-Shift                  for the red symbols
  1151.     F1               Caps-Shift+1                  EDIT (Edit BASIC-line)
  1152.     F2,CapsLock      Caps-Shift+2                  CAPS LOCK
  1153.     F3,Tab           Caps-Shift+3                  TRUE VIDEO
  1154.     F4               Caps-Shift+4                  INVERSE VIDEO
  1155.     Cursor left      Caps-Shift+5                  Move cursor left
  1156.     Cursor down      Caps-Shift+6                  Move cursor down
  1157.     Cursor up        Caps-Shift+7                  Move cursor up
  1158.     Cursor rechts    Caps-Shift+8                  Move cursor right
  1159.     F9               Caps-Shift+9                  GRAPHICS-MODE
  1160.     Delete,BS        Caps-Shift+0                  DELETE
  1161.     F10              Caps-Shift+Space              BREAK (Stop Program)
  1162.     <                Symbol-Shift+O                ; (Semicolon)
  1163.     ~                Symbol-Shift+P                " (Quote)
  1164.     ß                Symbol-Shift+C                ? (Questionmark)
  1165.     ä                Symbol-Shift+L                = (Equates)
  1166.     ö                Symbol-Shift+Z                : (Colon)
  1167.     ü                Symbol-Shift+2                @ (Absatz)
  1168.     Alternate-4      Symbol-Shift+4                $ (Dollar)
  1169.     Alternate-5      Symbol-Shift+5                % (Percent)
  1170.     Control-LShift-P EXTENDED-MODE-Shift-P         © (Copyright)
  1171.   
  1172.     Emulator-Controlkeys (Default-Layout)
  1173.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1174.   
  1175.     Key              Action
  1176.     -----------------------------------------------------------------------
  1177.     F5               Load or save Snapshot-File
  1178.     F6               Reset the Z80
  1179.     Shift-F6         Quit the emulator
  1180.     Alternate-F6     Trigger NMI (Non-Maskable-Interrupt)
  1181.     F7               Toggle Sound-Mode
  1182.     F8               Return to Shell (in Shell-Mode)
  1183.     Esc              Call Z80-Monitor/Disassembler
  1184.     Help             Show Help-Screen
  1185.     Insert           Break emulation, shows menu (Alert/Setup)
  1186.     Undo             Switch emulation-sets
  1187.     Home             (not used)
  1188.   
  1189.   
  1190.   B: SOME ZX-SPECTRUM INTERNALS
  1191.   =============================
  1192.   
  1193.    memory layout (adressrange: 0-65535)
  1194.   -------------------------------------------------------------------------- 
  1195.    00000-16383   ROM
  1196.    16384-22527   Display file (pixel data) 
  1197.    22528-23295   Attribut file (Colours and attributes per character)
  1198.    23296-23551   Printer buffer (used as temporary memory often)
  1199.    23552-23733   System variables (see below for examples)
  1200.    23734-23754   Systemspace for I/O
  1201.    23755-        BASIC program memory + variables 
  1202.    In high memory lie areas of systemspace, stacks and user-graphics.
  1203.   
  1204.    Interesting system variables:
  1205.    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1206.   
  1207.    (Words are stored in low-high format!)
  1208.   
  1209.    adress  length name     description
  1210.    -------------------------------------------------------------------------- 
  1211.    23560     1    LAST_K   Newly pressed key (if bit 5 of FLAGS is set)
  1212.    23561     1    REPDEL   Time in 1/50 seconds for key to repeat
  1213.    23562     1    REPPER   Delay in 1/50 seconds between key repeats
  1214.    23606     2    CHARS    Pointer to character set - 256. Can be patched
  1215.                            to install own font.
  1216.    23609     1    PIP      Lenght of keyboard click (try for example 10)
  1217.    23608     1    RASP     Length of warning buzz.
  1218.    23610     1    ERR_NR   BASIC error number - 1. Starts off with 255 (-1).
  1219.                            Register IY always points to this adress in BASIC
  1220.    23611     1    FLAGS    Flags controlling the BASIC system.
  1221.    23613     2    ERR_SP   Adress of item on stack used as error return for
  1222.                            BASIC errors.
  1223.    23624     1    BORDCR   Border colour * 8; also contains the attributes
  1224.                            for the lower part of screen( input area).
  1225.    23627     2    VARS     Points to variables area of BASIC program
  1226.    23635     2    PROG     Points to program area of BASIC (normally 23755)
  1227.    23559     1    DF_SZ    Number of lines in input area of screen.
  1228.                            An often used simple method to crash the Spectrum
  1229.                            when BREAKing into program: Set DF_SZ to 0.
  1230.    23672     3    FRAMES   3 byte counter (low-high). Every 20 ms incremented
  1231.    23692     1    SCRCT    Number of scrolls of screen before the question
  1232.                            "scroll?" is shown.
  1233.    23728     2    NMI-ADD  Adress to which NMI jumps to. This does not work
  1234.                            in the original ROM, but it suffices to patch ROM
  1235.                            on adress $006D from $20 to $28 to make it work.
  1236.    23730     2    RAMTOP   Adress of the last memory byte for BASIC
  1237.    23732     2    P-RAMT   Adress of the last physical byte in memory
  1238.    
  1239.    Interesting system calls:
  1240.    ~~~~~~~~~~~~~~~~~~~~~~~~~
  1241.   
  1242.    RANDOMIZE USR 3280      Scroll up the screen by one line
  1243.    PRINT 65536-USR 7962    Show free memory
  1244.    RANDOMIZE USR 0         Soft reset of the Spectrum
  1245.   
  1246.   
  1247.   C: INFORMATION FOR PROGRAMMERS
  1248.   ==============================
  1249.   
  1250.    THE SNAPSHOT FORMAT
  1251.    -------------------
  1252.   
  1253.         #Byte    Contents                Comment
  1254.       --------------------------------------------------------------------
  1255.          0       I  register
  1256.          1       L' register
  1257.          2       H' register
  1258.          3       E' register
  1259.          4       D' register
  1260.          5       C' register
  1261.          6       B' register
  1262.          7       F' register
  1263.          8       A' register
  1264.          9       L  register
  1265.         10       H  register
  1266.         11       E  register
  1267.         12       D  register
  1268.         13       C  register
  1269.         14       B  register
  1270.         15       IY lower byte
  1271.         16       IY upper byte
  1272.         17       IX lower byte
  1273.         18       IX upper byte
  1274.         19       Bit 2 contains IFF2     other bits are irrelevant
  1275.         20       R  register
  1276.         21       Flag register
  1277.         22       A  register
  1278.         23       SP lower byte
  1279.         24       SP upper byte
  1280.         25       Interrupt mode          0, 1 or 2
  1281.         26       Border colour           0..7
  1282.       27..49178  48 kB RAM dump
  1283.   
  1284.   After loading the registers the program must be started by executing a RETN 
  1285.   instruction i.e. the program counter is on the stack (in RAM dump).
  1286.   
  1287.   
  1288.    THE EXTENDED SNAPSHOT FORMAT
  1289.    ----------------------------
  1290.   
  1291.         #Byte    Contents                Comment
  1292.       --------------------------------------------------------------------
  1293.          0..3    "XSNA"                  Identification for emulator
  1294.          4,5     Header lenght           #Bytes in following header
  1295.          6..32   Register                as in SNA standard format
  1296.          33..42  Emulator switches       if1sw - im2hw of setup area
  1297.   ab 43:
  1298.          2 Bytes count                   Number of bytes in block ***)
  1299.          1 Byte  Flag                    Mark if "compressed" block
  1300.   either (Flag = $ff):
  1301.          1 Byte  Fill value              Byte to be repeated count times
  1302.   or     (Flag = 0):
  1303.          Count bytes data                without compression
  1304.   
  1305.   ***) Optimisation, if number of bytes in block <= 16 !!!
  1306.        The first byte of count contains a value >= $E0, that is to interpret
  1307.        in the following way:  the lower nibble contains the byte count - 1,
  1308.                               the upper nibble is $E for an uncompressed
  1309.                               block, $F für a compressed block.
  1310.        The second count byte and the flag byte are not present in this case !
  1311.   
  1312.   The blocks from byte 43 on are repeated for the whole ram dump.
  1313.   
  1314.   
  1315.    EMULATOR PATCH AREA FOR SPECTRUM ROM
  1316.    ------------------------------------
  1317.   
  1318.   The Spectrum ROM is patched into the emulator file "SPECCI.DAT" from offset 
  1319.   34  on  (length:  16384 bytes). Immedeatly behind follow the 8192 bytes for 
  1320.   the interface-1 rom.
  1321.   
  1322.    HOW TO INSTALL AN OWN SCREEN DRIVER
  1323.    -----------------------------------
  1324.   
  1325.   During  initialization  of the emulator after it has been started, it looks 
  1326.   for  a  file named "ZXVID.TRB" in the emulator directory. If it is present, 
  1327.   it will be interpreted as an external screen driver and loaded into memory. 
  1328.   "ZXVID.TRB"  has to be an executable program (just renamed) and also has to 
  1329.   be  completey position-independant i.e. must only use PC-relative adressing 
  1330.   modes. It must have a header of the following scheme:
  1331.   
  1332.        { 28 bytes program header of an executable file }
  1333.   
  1334.   vdrv_hdr  equ   *
  1335.             bra.w     v_install         ; Installation               +0
  1336.             ds.l      1                 ; De-Installation            +4
  1337.             ds.l      1                 ; Screenbyte with attribute  +8
  1338.             ds.l      1                 ; Screenbyte without attr.   +12
  1339.             ds.l      1                 ; BORDER display             +16
  1340.             ds.l      1                 ; Display of whole screen    +20
  1341.             ds.l      1                 ; VBL task (during LOADing)  +24
  1342.   
  1343.   
  1344.   The  first  longword  contains  a branch to an installation procedure. This 
  1345.   procedure will receive the following values from the emulator:
  1346.   
  1347.   a1 .... Pointer to ZX-screen within emulator ram (= data to display)
  1348.   a0 .... Pointer to a buffer, that the driver my freely use
  1349.   d0 .... Length of this buffer
  1350.   a4 .... Pointer to emulator variables beeing needed for display:
  1351.           0(a4) contains a switch for attribute display (0=no)
  1352.           1(a4) contains a switch for FLASH display     (0=no)
  1353.           2(a4) contains the momentary FLASH state (0=normal, $ff=invers)
  1354.   
  1355.   The  installation  routine  has  to  save  these  values, do any neccessary 
  1356.   initializations  to  it's data. Also it must complete the header by filling 
  1357.   in  the  adresses  of  the  procedures doing the appropriate tasks (display 
  1358.   single screen byte with/without attribute, ...).
  1359.   
  1360.   A return value must be put into the register d0.w:
  1361.   
  1362.       0 = ok, everything installed correctly
  1363.       1 = wrong screen resolution
  1364.       All other values signal other errors
  1365.   
  1366.   Return to the emulator is done with a  RTS instruction. No register must be 
  1367.   saved by the initialization procedure.
  1368.   
  1369.   The runtime procedures must preserve all registers !!!
  1370.   
  1371.   An  example-driver  (for  ST  medium resolution, which of course is not too 
  1372.   useful)  is  included  as source file (MIDRES.S), where you could study the 
  1373.   implementation of the above description in detail.
  1374.   
  1375.    START OF EMULATOR THROUGH EMULATOR SHELL
  1376.    ----------------------------------------
  1377.   
  1378.   If  the emulator finds a string "/s" in its command line, it tries to start 
  1379.   a  shell  program.  This  shell  program  will  then be able to control the 
  1380.   emulator  by  using  it  just  like  a  subroutine. By this way it would be 
  1381.   possible  to  build  a  shell  of  any  complexity around the emulator, for 
  1382.   example  an  own  desktop  or  a  GEM  window  on  the  (Multi-TOS-)desktop 
  1383.   controlling the emulator.
  1384.   
  1385.   The  string  "/s" can optionally be followed by the (path)name of the shell 
  1386.   program,  for  example  "/sG:\SPECCI\SPSHELL.PRG". If none is specified the 
  1387.   name  entered  for  the  program  for key "F8" in the configuration will be 
  1388.   used.
  1389.   
  1390.   The  supplied  program  "SPSHELL.PRG"  is  a good example, how such a shell 
  1391.   program  works.  If  called  from  the  desktop,  it enters the string "/s" 
  1392.   followed  by its own name, which it request through the function SHEL_READ, 
  1393.   in a commandline and passes it to the emulator program via SHEL_WRITE. Then 
  1394.   it  ends  itself.  SHEL_WRITE will now start the emulator automatically, it 
  1395.   will  find the string "/sSPSHELL.PRG" in its commandline and will start the 
  1396.   shell  program  on  its  own  again.  The  shell  program  now realizes the 
  1397.   situation  and  now  starts  its designed job as interface to the emulator. 
  1398.   This  whole  procedure may sound somewhat irritating, but it functions very 
  1399.   well.
  1400.   
  1401.    COMMUNICATION WITH EXTERNAL PROGRAMS
  1402.    ------------------------------------
  1403.   
  1404.   The  basis  for communication with the emulator is the knowledge of certain 
  1405.   adresses  within the emulator program, where various informations are kept. 
  1406.   These adresses will be supplied the external program by the commandline.
  1407.   
  1408.         #Byte    Contents     Comment
  1409.       --------------------------------------------------------------------
  1410.           0       '©'         Special identification (called from emulator)
  1411.           1       64          Number of bytes following
  1412.           2..9    HHHHHHHH    Adress setup data
  1413.           10..17  HHHHHHHH    Adress Z80 adress space within Atari
  1414.           18..25  HHHHHHHH    Adress emulator variables
  1415.           26..33  HHHHHHHH    Adress Atari screen buffer
  1416.           34..41  HHHHHHHH    Adress for return value
  1417.           42..49  0000000H    Number of active set 0..3
  1418.   
  1419.   Thereby H is representing an hexadecimal character in ascii format i.e. "0" 
  1420.   to "9" or "A" to "F".
  1421.   
  1422.   The  "identificaton" in byte 0 serves to enable the program to detect, that 
  1423.   it is called from the emulator, so it may behave differently as when called 
  1424.   from the desktop.
  1425.   
  1426.    The pointer to the setup data...
  1427.    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1428.   
  1429.    ...points to the following structure:
  1430.   
  1431.         #Byte      Contents     Comment
  1432.       --------------------------------------------------------------------
  1433.           0..7     'ZXSP2.00'   ID string, with emulator version number
  1434.           8..807   800 Bytes    Setup data as follows:
  1435.                    160 Bytes    Data set #1
  1436.                    160 Bytes    Data set #2
  1437.                    160 Bytes    Data set #3
  1438.                    160 Bytes    Data set #4
  1439.                    160 Bytes    Data active set (working copy)
  1440.   
  1441.    Setup data contain the following values:
  1442.   
  1443.       Name       Length  Description
  1444.      ------------------------------------------------------------------------
  1445.       prgpfad    35      Path for program files, null terminated
  1446.       mdrpfad    35      Path for microdrive data, null-terminated
  1447.       mdid       7       Filename microdrives (without number), null term.
  1448.       snapfad    35      path for SNA/SNA files, null terminated
  1449.       spalett    32      16 word colour palette for 320x200
  1450.       illsw      1       switch Z80 Illegal: 0=Alert, 1=Monitor, 2=Ignore
  1451.       errsw      1       switch Emu error  : 0=Alert, 1=Monitor, 2=Reset
  1452.       sna_sw     1       switch SNA format : 0=SNA, 1=SNX
  1453.       autosw     1       switch AUTO.SNA:  Bit 0=at start, Bit 1=at RESET
  1454.       ulasw      1       switch ULA-compatible display:  Bit 7 set=ON
  1455.       vblseq     1       Sequence pattern VBL display, bit-coded.
  1456.                          Is not used in version 2.07 (earlier versions did).
  1457.       if1sw      1       switch Interface 1: 0=not emulated, 1=emulated
  1458.       flashsw    1       switch FLASH:       0=not emulated, 1=emulated
  1459.       attrsw     1       switch Attributes:  0=no attributes,1=attributes
  1460.       zy_sw      1       switch keys Z-Y:    Bit 7=0 QWERTY, 1=QWERZ
  1461.                          +joystick emulation Bit 0,1 00=Kempston
  1462.                                                      01=IF1/1
  1463.                                                      10=IF2/2
  1464.                                                      11=Cursor
  1465.                          Bit 6 contains ULA-emulation from Version 2.07 on.
  1466.                          (0=off, 1=on). 
  1467.       r_sw       1       switch R-register:0=R not emulated, 1=R emulated
  1468.                          Bit 7 is used as value for the EAR-bit.
  1469.       int_sw     1       switch interrupt frequency: 0=50Hz, 1=100Hz
  1470.       rs232sw    1       switch RS232 redirection:  Bit 0=RS232, Bit 1=CENTR.
  1471.       sndsw      1       switch sound emulation:
  1472.                          Lower nibble:  0=OFF,1=direct,2=Interrupt
  1473.                          Higher nibble: frequency 0..4 for mode 2
  1474.       bordsw     1       switch border emulation: 0=OFF,1=direkt,2=Interrupt
  1475.       im2hw      1       switch IM2 hardware vector 0..255
  1476.       free       1       NOT USED
  1477.       rom_load   1       switch external ROM: 0=do not load, 1=load
  1478.       rom_pfad   36      path for external ROM file, null terminated
  1479.       cnfg_e     1       Configuration byte external programs:
  1480.                          Bit 0: key ESC
  1481.                          Bit 1: key F5
  1482.                          Bit 2: key F8
  1483.                          Bit 3: key CLR/HOME
  1484.                          Bit 4: key INSERT
  1485.                          Bit 5: key HELP
  1486.                          Bit 6: key UNDO
  1487.                          Bit 7: not used
  1488.       cnfg_s     1       Configuration byte shell mode (bits like cnfg_e)
  1489.       esc_prg    14      Name/Configuartion for program on key ESC
  1490.                          Bytes 0..12 contain the name
  1491.                          Byte  13 contains parameter for start:
  1492.                          Bit 0:  Restore colour palette
  1493.                          Bit 1:  Load resident
  1494.                          Bit 2:  Run in ZX-mode
  1495.                          Bit 3:  Evaluate return value
  1496.                          Bit 7:  Can be activated by left mouse click
  1497.       f5_prg:    14      Name/configuration for program on key F5
  1498.       f8_prg     14      Name/configuration for program on key F8
  1499.       clr_prg    14      Name/Configuration for program on key CLR/HOME
  1500.       ins_prg    14      Name/Configuration for program on key INSERT
  1501.       help_prg   14      Name/Configuration for program on key HELP
  1502.       undo_prg   14      Name/Configuration for program on key UNDO
  1503.   
  1504.   
  1505.    The pointer to the Z80 adress space...
  1506.    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1507.   
  1508.   ...points  to the ram adress within the emulator, where the emulated adress 
  1509.   space  of  the ZX-Spectrums Z80 processor starts. The first 16384 bytes are 
  1510.   the ROM area.
  1511.   
  1512.    The pointer to the emulator variables...
  1513.    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1514.   
  1515.   ...points  to  a  data area that contains besides various other values, the 
  1516.   contents of the emulated Z80 registers:
  1517.   
  1518.   
  1519.        Offset  Name     Length  Description
  1520.       --------------------------------------------------------------------
  1521.        -14     request  BYTE    Request typ interruption (Scancode of key)
  1522.                                 By examining this value the external program
  1523.                                 may determine which key activated it.
  1524.        -13     shell    BYTE    Is 1 in Shell-mode, 0 in desktop mode
  1525.        -12     lstkey   BYTE    Last key pressed in Spectrum mode
  1526.        -11     SPECTRUM BYTE    Spectrum mode: 0=OFF $ff=ON
  1527.        -10     zeropage LONG    Pointer to Z80 adress space in Atari
  1528.        -6      fcount   BYTE    Counter for FLASH emulation
  1529.        -5      bcount   BYTE    Counter for BORDER emulation
  1530.        -4      attr_sw  BYTE    Runtime copy of attrsw-switch
  1531.        -3      flash_sw BYTE    Runtime copy of flashsw-switch
  1532.        -2      fmode    BYTE    Flash cycle ($ff=INVERS)
  1533.        -1               BYTE    (not used at the moment)
  1534.   
  1535.     ->  0      z80_regs 40 BY   Emulated Z80 registers in this sequence:
  1536.         0      _H       BYTE    H-register
  1537.         1      _L       BYTE    L-register
  1538.         2      _D       BYTE    D-register
  1539.         3      _E       BYTE    E-register
  1540.         4      _B       BYTE    B-register
  1541.         5      _C       BYTE    C-register
  1542.         6      _XH      BYTE    Upper byte IX-register
  1543.         7      _XL      BYTE    Lower byte IX-register
  1544.         8      _YH      BYTE    Upper byte IY-register
  1545.         9      _YL      BYTE    Lower byte IY-register
  1546.        10      _I       BYTE    I-register
  1547.        11      _R       BYTE    R-register
  1548.        12      _A       BYTE    Accumulator
  1549.        13      _A'      BYTE    Alternative Accumulator
  1550.        14      _H'      BYTE    Alternative H-register
  1551.        15      _L'      BYTE    Alternative L-register
  1552.        16      _D'      BYTE    Alternative D-register
  1553.        17      _E'      BYTE    Alternative E-register
  1554.        18      _B'      BYTE    Alternative B-register
  1555.        19      _C'      BYTE    Alternative C-register
  1556.        20      _SF      BYTE    S-bit (Sign) of status register
  1557.        21      _ZF      BYTE    Z-bit (Zero) of status register
  1558.        22      _U1F     BYTE    Unused bit of status registers
  1559.        23      _HF      BYTE    H-bit (Half-Carry) des status registers
  1560.        24      _U2F     BYTE    Unused bit des status registers
  1561.        25      _VF      BYTE    V-bit (Overflow) des status registers
  1562.        26      _NF      BYTE    N-bit of status registers
  1563.        27      _CF      BYTE    C-bit (Carry) ofstatus registers
  1564.        28      _SF'     BYTE    S-bit (Sign) of alt. status registers
  1565.        29      _ZF'     BYTE    Z-bit (Zero) of alt. status registers
  1566.        30      _U1F'    BYTE    Unused bit of alt. status registers
  1567.        31      _HF'     BYTE    H-bit (Half-Carry) of alt. status registers
  1568.        32      _U2F'    BYTE    Unused bit of alt. status registers
  1569.        33      _VF'     BYTE    V-bit (Overflow) of alt. status registers
  1570.        34      _NF'     BYTE    N-bit of alt. status registers
  1571.        35      _CF'     BYTE    C-bit (Carry) of alt. status registers
  1572.        36      _SP      WORD    SP-register (Stack pointer) HI-LO
  1573.        38      _PC      WORD    PC-register (Program counter) HI-LO
  1574.   
  1575.        40      iff      WORD    Z80 Interruptflipflop(s):
  1576.        40      iff1     BYTE    Interruptflipflop 1; $ff=enabled, $00=disabl.
  1577.        41      iff2     BYTE    Interruptflipflop 2; storage for iff1
  1578.        42      intmode  WORD    Z80 Interruptmode: IM0=-1, IM1=0, IM2=1
  1579.        44      akt_bc   WORD    Active border colour SHOULD BE
  1580.        46      old_bc   WORD    Active border colour IS ACTUALLY
  1581.        48      old_a7   LONG    Internal storage for a7
  1582.        52      brk_flg  BYTE    Flag breakpoint for monitor
  1583.        53      mon_flg  BYTE    Monitor call: 0=User, 1=BREAK, 2=Illegal
  1584.        54      r_bit7   BYTE    Bit 7 of R-register
  1585.        55      new_requ BYTE    New request. By setting this value external
  1586.                                 programs can request activation of another
  1587.                                 program (scancode of key) after return (see
  1588.                                 -14 request).
  1589.        56      ports    12 BY   Soft ports of Z80:
  1590.        56               WORD    Filler, so that gets offset > 0!
  1591.        58      port_b0  BYTE    value for bit 0 of port adress
  1592.        59      port_b1  BYTE    Value for bit 1 of port adress
  1593.        60      port_b2  BYTE    Value for bit 2 of port adress
  1594.        61      port_b3  BYTE    Value for bit 3 of port adress
  1595.        62      port_b4  BYTE    Value for bit 4 of port adress
  1596.        63      port_b5  BYTE    Value for bit 5 of port adress
  1597.        64      port_b6  BYTE    Value for bit 6 of port adress
  1598.        65      port_b7  BYTE    Value for bit 7 of port adress
  1599.        66      port_31  BYTE    Value for port 31 (Kempston joystick)
  1600.        67      port_xx  BYTE    unused (reserved)
  1601.   
  1602.    The pointer to the Atari screenbuffer...
  1603.    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1604.   
  1605.   ... points to a area of memory where the last shown Spectrm screen in Atari 
  1606.   32K-format  has been put. Very practical for each external program that can 
  1607.   use the Spectrum screen in any way (print hardcopy, store as IMG file, ..).
  1608.   
  1609.    The pointer to the return value...
  1610.    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1611.   
  1612.   ...serves  for  the  communication  with  the emulator. By entering certain 
  1613.   values  into  this  adress, the emulator can be brought to perform specific 
  1614.   actions, after it gained control again:
  1615.   
  1616.       (zx_ret.w)       Action after return
  1617.       ------------------------------------------------------------------
  1618.         0              MUST NOT BE!!
  1619.         1              Quit emulator (Desktop)
  1620.         2              Perform ZX reset
  1621.         3              Load snapshot, path must be at (screenbuffer).
  1622.         4              Save snapshot, path must be at (screenbuffer).
  1623.         5              Trigger NMI
  1624.         99             Ignore all changes in set (CANCEL in SPSETUP)
  1625.   
  1626.   
  1627.   
  1628.   If  an  external  program has been configured to return a value, it must in 
  1629.   all  instances  put a non-zero value into (zx_ret.w) and the number for the 
  1630.   active  set  into  (zx_ret+2.w) because a zero-value will tell the emulator 
  1631.   that  activation  failed.  The  value 99 can be used as "CANCEL"-value - in 
  1632.   this  case  no  return  value  will  be  evaluated  and emulation continues 
  1633.   immedeatly.
  1634.   
  1635.   Always  when  a  return  value  other than 99 is entered there MUST also be 
  1636.   entered the number of the active set into adress (zx_ret+2.w), which has to 
  1637.   be  a value between 0 and 4! Values from 0 to 3 will initiate a copy of the 
  1638.   corresponding  set  into the work area (and setting of internal variables). 
  1639.   The  value 4 effects that the working set is left unchanged after return to 
  1640.   the emulator.
  1641.   
  1642.    The number of the active set of switches...
  1643.    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1644.   
  1645.   ...for  all  programs,  that  rely on the knowledge, which set is currently 
  1646.   active, like the program "SPSETUP.PRG".
  1647.   
  1648.