home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / emulate / z80emula.lzh / Z80Intro < prev    next >
Text File  |  1992-07-15  |  34KB  |  677 lines

  1. Introduction to Z80 Emulator / Cross Developer V1.03
  2.  
  3. Written by Phil Brown, Copyright 1992
  4.  
  5. This  program  formed  the basis of my final year individual project for my
  6. Masters  degree  in Software Engineering at Imperial College, UK.  The work
  7. contained within it is entirely my own so I take full responsibility for it
  8. and any credit, if it is due.
  9.  
  10. The  program  is not being written for financial reward and I ask for none.
  11. This program may be copied, transferred, posted and distributed freely.  If
  12. you  use  this  program, then it would be nice if you could let me know and
  13. tell  me what you are using it for, as this may affect future developments,
  14. and I will derive pleasure from this.  Please don't send me money.  I don't
  15. expect  this  program to make me a millionaire, and if there is someone out
  16. there  who  finds it useful then that is just reward for all the neat stuff
  17. with  which others have provided me.  At some later date (very much later),
  18. this program may evolve into a shareware product so if you feel the urge to
  19. shower  me  with  gifts  then  hold  on until I feel justified in accepting
  20. remuneration  for  the  product, or spend it on your girlfriend/partner.  I
  21. know which I would choose.
  22.  
  23. Please  note that this is a product under development.  It is supplied with
  24. no  guarantees.  Use it at your own discretion.  I will however gladly give
  25. support to this product.
  26.  
  27. What you will need:
  28.  
  29. - A Commodore Amiga with about 50K CHIP and 200K FAST memory available.
  30.  
  31. - Preferably some experience or understanding of the Zilog Z80 CPU.
  32.  
  33. I  don't intend to describe the intricacies or workings of the Z80 here, so
  34. in  the  following  documentation  I'll  use standard Z80 mnemonics without
  35. further  explanation.   Those who don't understand these will probably find
  36. this program fairly useless anyway.
  37.  
  38. The philosophy behind this program:
  39.  
  40. This  program  was  written to investigate the levels at which a CPU can be
  41. emulated  in  software.   More  on  this  later.   As  such it comprises an
  42. emulation  of  all  the  internal registers of the Z80, a 64K memory map, a
  43. complete   cross-assembler  and  disassembler  and  a  simple  interpretive
  44. emulation  routine which should simulate all the effects of instructions on
  45. a  Z80.   Furthermore  an "abstract machine" is provided which looks like a
  46. console  screen  and  keyboard to the Z80, responding via IN and OUT ports,
  47. but  which  provides  a "bridge" to the peripherals and devices of the host
  48. computer (the Amiga).
  49.  
  50. It  was  not  written  to  emulate  any one particular system, although the
  51. highly modular nature of the code means that new abstract machines, methods
  52. of  software  emulation and even CPUs may be added very easily.  The code I
  53. have  written  provides  a  core system around which I may add other things
  54. very  easily  for  my research.  However, as it stands it provides a fairly
  55. complete cross-development system for Z80-based targets.
  56.  
  57. For  those  interested parties the program is written entirely in Modula-2.
  58. Untrendy  it may be but my Benchmark compiler gets the job done in half the
  59. time  of  a  C compiler.  The program was developed initially on a 1.3 A500
  60. with a 25MHz MegaMidgetRacer 68030 accelerator and latterly on a 2.0 A1500.
  61. I  see  no  reason  why  it  should  not  work on all systems as I don't do
  62. anything  even faintly naughty.  Previous users note:  the program now read
  63. in   the   size   of   Workbench  screen  and  uses  the  same  parameters.
  64. Unfortunately  the one exception to this is SuperHiRes screens (ie having a
  65. super hires workbench results in an ordinary HiRes Emulator).
  66.  
  67. What you currently get:
  68.  
  69. - A representation of the internal registers of the Zilog Z80 CPU. These
  70.   include all the nasty things like the Half Carry register, IFF1 and
  71.   IFF2 and the Parity/Overflow flag.
  72.  
  73. - A simulated 64K address space.
  74.  
  75. - A single pass assembler.
  76.  
  77. - A symbolic disassembler.
  78.  
  79. - Some debugging tools.
  80.  
  81. - An emulated console.
  82.  
  83. - An interpretive emulator.
  84.  
  85. - An optimised emulation cycle for 25% more throughput at the expense of
  86.   memory usage.
  87.  
  88. - A translator from a program image in memory to standard 'C' source which
  89.   can then be separately compiled and linked to a run-time support library
  90.   for blistering throughput. This may not be present on all versions; I am
  91.   currently extending and optimising this process.
  92.  
  93. Please  note  that  this  emulator  was  not designed for speed and gives a
  94. throughput  of  about 4000 instr/sec on a 25MHz '030 system.  Incidentally,
  95. the   emulator   is   designed  to  be  reasonably  portable  and  all  the
  96. Amiga-specific  stuff  is  contained  in one module.  There's no reason why
  97. porting to another system shouldn't be very trivial.
  98.  
  99. Central  to  the  design  of the system is the Abstract Instruction Format.
  100. When  I  started  designing  the program it became obvious that significant
  101. benefits  in  design and modularity could be released if I introduced a new
  102. representation   of  a  Z80  instruction.   Let  me  explain  this  a  bit.
  103. Traditionally  there  are  two  representations  for  an  instruction;  the
  104. mnemonic  string  eg LD A,(IX+23) and the byte-code eg 253,126,23.  Now the
  105. first  stage  of  disassembling and emulation is the same, to work out what
  106. the  heck  these  little  strings  of  1's  and  0's  really mean, the only
  107. difference  being that when disassembling you display the mnemonic and when
  108. emulating you simulate the effects.
  109.  
  110. Normally  the  code to display the instruction or emulate it is threaded in
  111. amongst  the  disassembly of the byte codes.  This would result in two very
  112. similar  routines,  which is unsatisfactory from a design elegance point of
  113. view,  and also makes the code less legible and more difficult to debug and
  114. maintain.  Similar problems exist when considering assembly and interactive
  115. emulation.   Say we want the user to be able to type in an instruction from
  116. a  prompt  and  see the effects; normally it would be necessary to assemble
  117. this string into some place in memory and emulate it from there.
  118.  
  119. What  I  decided  to  do  was to introduce a structure which stored all the
  120. information  held within an instruction in an easily accessible form.  This
  121. was  used  to move between the different representations.  For example, the
  122. first  phase  of  disassembly  and emulation is now the same; to decode the
  123. bytes  into an abstract instruction, then this abstract structure is either
  124. displayed  (via  a  simpler  decoding  routine)  or emulated.  The abstract
  125. instruction thus lies between the two traditional representations:
  126.  
  127.                         Instruction Mnemonic
  128.                             LD A,(IX+23)
  129.  
  130.                               |    ^
  131.                               |   /|\
  132.                    Parser     |    |     Decoder
  133.                              \|/   |
  134.                               V    |
  135.                                                       \
  136.                         Abstract Instruction ----------> Emulator
  137.                                LOAD,                  /
  138.                           Direct Register A,
  139.                Indirect Register pair IX displaced 23
  140.  
  141.                               |    ^
  142.                               |   /|\
  143.                 Assembler     |    |     Disassembler
  144.                              \|/   |
  145.                               V    |
  146.  
  147.                              Byte Code
  148.                             253,126,23
  149.  
  150. This  structure  gives the code great modularity and is also quite elegant.
  151. Thus  disassembly  to  mnemonic  form  now  disassembles  from byte code to
  152. abstract format, and is decoded from that to the mnemonic string.  This has
  153. a performance hit but is not too bad.
  154.  
  155. Now the most useful bit: how to use the program.
  156.  
  157. First  the  good news:  most functions can be accessed from a typed command
  158. interface, or from a menu.
  159.  
  160. Now  the  bad news:  menus are not completely implemented.  Any menu option
  161. which  is  interactive (such as a defining a filename to load or save) will
  162. give a strange error message (strange to you, not to me!), normally telling
  163. you that you have not defined all required parameters.  Why is this?  Well,
  164. my  Modula-2  compiler  had  great difficult interfacing to the req.library
  165. that  I wanted to use and in the end I had to give up, as even the assembly
  166. language interface to the compiler is bugged.  Sorry about this.  If a menu
  167. command  doesn't  work  then  use  the  command line.  Menu items currently
  168. affected  are:   Load, Save, Disassemble, Dump, Initialise and Copy memory.
  169. All others should work OK.
  170.  
  171. When  the  program  is fired up (from the CLI, Workbench, Runbacked or just
  172. about any other way you fancy) you will be presented with a screen with the
  173. same characteristics as your Workbench, split into two sections.  The first
  174. section,  occupying  the  top  seven  lines  of the screen show the current
  175. register contents.  The second section is your interactive command section,
  176. and  where  most responses to your commands will happen.  It recognises and
  177. uses  your system fonts and menu fonts, resising windows appropriately.  If
  178. your  font  is too large you may want to use the FONT command to change the
  179. default.
  180.  
  181. If  the output to the screen is whizzing by too fast, then the simplest way
  182. of  doing  this is to press the right mouse button (or pressing Right Amiga
  183. and  Rigth  Alt) which brings up the menu bar and halts output until one of
  184. these  is  released.   I  included  at  one  time  a  scrollback buffer and
  185. proportional  gadget,  but for various aesthetic and technical reasons this
  186. had to be dropped.
  187.  
  188. The program knows about a "current number base" which is the number base in
  189. which  values  will  be  displayed.   This can be Binary, Octal, Decimal or
  190. Hexadecimal.   On  startup the system is in Decimal mode (sorry all you hex
  191. fans,  it's  what I grew up with on the Z80.  It's strange; for some CPUs I
  192. think  in  hex,  for others in decimal...maybe I'm just wierd).  You can of
  193. course change this by simply selecting an item from the Settings menu or by
  194. typing a command, or by using a startup script.
  195.  
  196. Before  I start banging on about the individual functions, there's a couple
  197. of  things  I should mention.  The command parser is pretty flexible.  It's
  198. handled  by  a  database  which  details for each command the parameters it
  199. expects,  their  type  and  whether  they  are  optional  or required.  The
  200. commands  may be accessed by typing as much of the command as required eg D
  201. is  adequate  for  DISASSEMBLE, but at least DU is required for DUMP.  Each
  202. parameter  has  a keyword associated with it (unless it is a flag) and this
  203. may  be used to identify the following parameter.  If the parameter keyword
  204. is  missing  then  positional  placement  dictates which parameter is being
  205. defined.   Hmm.   I  have  not  defined  this too well methinks.  Here's an
  206. example.  The template for DISASSEMBLE is:
  207.  
  208. DISASSEMBLE <START Address> [END Address] [FILE FileName] [NOLABELS]
  209.  
  210. What  this  means  is that the first parameter is required and is the start
  211. address.  The other three are optional and the last is a flag which acts as
  212. a  switch.   Of  course  any or all of the command may be in upper or lower
  213. case.  If the user types:
  214.  
  215. D 0 100 Prog.ASM nolabels
  216.  
  217. Then the absence of keywords means that position dictates which is which so
  218. disassembly  starts from 0, ends at 100, output is to the file Prog.ASM and
  219. symbolic disassembly is switched off.
  220.  
  221. If, however, the user types:
  222.  
  223. DISASSEMBLE FILE Prog.ASM NOLABELS END 100 START 0
  224.  
  225. then  the parser will locate the parameters according to their keywords and
  226. the  result will be the same as previously.  The template may also indicate
  227. a  switch  list,  such  as  [  ON  |  OFF ] which specifies that one of the
  228. switches may be defined.
  229.  
  230. Furthermore, when a numeric parameter is required (such as an Address), the
  231. expression  handler  utilised  in  the  assembler is used.  This means that
  232. expressions  containing  symbols  may  be  used.   Standard  precedence  is
  233. observed.   Therefore, assuming the labels are defined in the symbol table,
  234. the user may type the following:
  235.  
  236. DISASSEMBLE MY_LABEL*10-20 END_CODE
  237.  
  238. and  the  expressions  will  be  evaluated  and  passed  to  the routine as
  239. expected.   If  the user wants to define a filename which contains a space,
  240. double quotes may be placed around the name.
  241.  
  242. Also,  any  numbers  specified  as  parameters will be assumed to be in the
  243. current  default number base.  If the user wishes to override this then the
  244. following prefixes may be used:
  245.  
  246. % - Binary
  247. & - Octal
  248. # - Decimal
  249. $ - Hexadecimal
  250.  
  251. eg %01111111, &177, #127, $7F all represent the same decimal value of 127.
  252.  
  253. I'll now describe in detail what those commands mean and what they do.
  254.  
  255. ASSEMBLE [FILE FileName] [START Address]
  256.  
  257. Initiates  assembly of the specified file to the specified address.  If the
  258. file  is  not  specified, or if the special token 'INLINE' is used then the
  259. input will be interactively from the keyboard, rather than from a file.  If
  260. the  start  address  is  not  specified then the current value of the PC is
  261. used.   Of  course, most programs will have an ORG directive as their first
  262. line anyway.  When assembling interactively, a colon ":" prompt rather than
  263. the  standard  arrow  ">"  will  be used.  The user should use the standard
  264. directive  END  to  terminate  assembly.  Each incarnation of the assembler
  265. clears  the  symbol  table  of  all  non-global  labels  (eg  assembler and
  266. disassembler-generated labels).
  267.  
  268. A  word  about  the assembler.  It follows the Zilog assembler specs pretty
  269. closely,  but with the following exceptions.  Zilog use appended letters to
  270. distinguish  their  numeric  bases,  and  I  use  prepended  characters  as
  271. previously  noted.   The  DEFW and DEFB directives should allow a series of
  272. comma-separated  values.  This doesn't fit into the parser nicely and until
  273. I  have  time  to  change  it,  DEFW  and  DEFB  directives accept a single
  274. parameter  only  eg  DEFW  100,13563 should be changed to DEFW 100 and DEFW
  275. 13563 on separate lines.  Sorry about that.  Also labels may only appear in
  276. the  first  column,  although  the  trailing colon is optional.  Who places
  277. labels  in  between  operands  anyway?  Macros are currently not supported.
  278. The  DEFL  directive  is not supported (use the EQU directive instead), the
  279. rather  pointless  DEFT directive is not supported (use DEFS instead).  The
  280. only   operators  allowed  in  expressions  are  -,+,/,*.   Most  of  these
  281. limitations will be lifted when I have more time.
  282.  
  283. The  assembler  is  single pass.  When it comes across a forward reference,
  284. space  is  left  in  the assembled code and the reference is entered into a
  285. table.   When  assembly  is  complete this table is resolved to fill in the
  286. bytes   with  the  proper  values.   Any  references  remaining  unresolved
  287. indicates  an  error.   These may be defined by the user and resolved using
  288. interactive  commands  (see later).  The assembler is not emulated but runs
  289. as  compiled  68000  code.   Therefore  the address space of the Z80 is not
  290. adulterated by having lots of utilities scattered around.
  291.  
  292. A  note  on  relative  jumps.   There  appear  to  be two standards used in
  293. relative jumps; that defined by Zilog and that used by other people.  Zilog
  294. state  that  a  relative jump is offset from the first byte of the relative
  295. jump instruction.  Others say that because the operand is modified by -2 to
  296. allow  for  the  twice  incremented  PC  after fetching the instruction and
  297. operand,  the  jump  is  offset  from the byte of the immediately following
  298. instruction.   In  other words, in Zilog terms JR 0 is an infinite loop but
  299. others  say  JR  0  does  nothing.  I have adopted the Zilog usage as it is
  300. likely to be more widespread.
  301.  
  302. DISASSEMBLE <START Address> [END Address] [FILE FileName] [NOLABELS]
  303.  
  304. Initiates diassembly of byte code to the equivalent mnemonics.  The address
  305. from  which  to start disassembling is required.  If the END address is not
  306. defined  then  the  whole 64K map will be disassembled.  The user may press
  307. Escape  or select the Abort menu item to stop disassembly at any point.  If
  308. the  FILE  parameter  is defined then output will be directed to this file,
  309. otherwise  output  will  go  to  the screen.  By default the disassembly is
  310. symbolic;  so  any symbols present in the symbol table will be used to make
  311. the  disassembly  more  meaningful.   This  can  be  disabled  by using the
  312. NOLABELS switch.
  313.  
  314. If the disassembler is run in symbolic mode, then any jump instruction will
  315. have  its  destination address calculated and a label for that address will
  316. be  generated.  If the address is before the current disassembly point then
  317. obviously the label will not previously have been displayed, so the address
  318. is  displayed.   If  the destination address is forward, then the generated
  319. label is used.  Subsequent runs of the disassembler will use the previously
  320. generated  labels to produce more symbolic output.  Disassembler labels are
  321. cleared  each  time  the  assembler  is  run,  however  the user may retain
  322. important labels by declaring them as GLOBAL.
  323.  
  324. Because it is very difficult to distinguish data from code in a Z80 system,
  325. disassembling  data  will  normally produce fairly sensible-looking results
  326. (sensible  that  is, until the code is examined).  However, occasionally an
  327. illegal  byte  code sequence will be produced (this will only happen in the
  328. case  of instructions extended by the hex CB, DD, ED and FD bytes.  When an
  329. illegal  sequence is detected, a DEFB directive of the first offending byte
  330. in  the  sequence  is output, and disassembly continues from the next byte.
  331. However  in  certain  cases  if required to disassemble an illegal extended
  332. instruction  for which there is an nonextended equivalent, the disassembler
  333. will  not  produce  an  error  but  will  output  the  nonextended  (legal)
  334. instruction.    For   example:   bytes  DD,60  has  no  legal  (documented)
  335. instruction,  but  the  disassembler will produce the mnemonic LD H,B which
  336. has   byte  code  60.   When  checking  my  assembler  and  disassembler  I
  337. reassembled  the  disassembly  of a 16K ROM and then disassembled it again.
  338. The  disassembled  output  was  identical  but the assembled code was three
  339. bytes  shorter  than  the  original!   This had me scratching my head for a
  340. while.   To  have the disassembler detecting these cases is an untidy piece
  341. of code on which I can't really justify spending time at the moment when it
  342. only   crops  up  when  you  disassemble  data  (or  possibly  undocumented
  343. instructions - see later).
  344.  
  345. CLEAR [ASSEMBLER | DISASSEMBLER | SYMBOLS | REFERENCES | PARSE]
  346.  
  347. The  entries  in the symbol table have a source associated with them.  This
  348. command  allows  the  user to clear selected parts of the symbol table.  If
  349. the  parameter defined is SYMBOLS then the entire table is cleared.  If the
  350. user  defines  the  REFERENCES  parameter  then  the  table  of  unresolved
  351. references  is  cleared.   If no parameter is supplied then both the symbol
  352. table   and  unresolved  reference  table  are  cleared.   Defining  either
  353. ASSEMBLER  or  DISASSEMBLER  causes  the appropriate symbols to be cleared.
  354. Defining  PARSE  clears  the  table of preparsed abstract instructions (see
  355. later).
  356.  
  357. BASE [BINARY | OCTAL | DECIMAL | HEXADECIMAL]
  358.  
  359. This  command  defines  the  default  number  base  for  the  system.  If a
  360. parameter  is  defined  then  this  becomes  the  new  number  base and one
  361. immediately  noticeable  effect  of  this  is  that  the register window is
  362. updated  to  reflect  their  values  in  the  new base.  If no parameter is
  363. supplied  then a message is displayed telling you what the current base is.
  364. Alternatively  the  Settings  menu  contains  an item to control the system
  365. number base.
  366.  
  367. EVALUATE <VALUE Value>
  368.  
  369. This  provides a primitive calculator service.  The user enters a number or
  370. expression  as the parameter and the result is displayed in the four number
  371. bases.
  372.  
  373. LOAD <FILE FileName> <START Address>
  374.  
  375. This  command  loads  a  byte  image of the specified file to the specified
  376. emulated  address  space.  If the file is longer then memory then it simply
  377. rolls-over and overwrites earlier portions of the file.
  378.  
  379. SAVE <FILE FileName> <START Address> <END Address | LENGTH Length>
  380.  
  381. Well  surprise  surprise this command saves a chunk of the emulated address
  382. space as a byte image.  The last parameter specifies either the end address
  383. or the number of bytes to write.  If the keyword is not present then LENGTH
  384. is assumed.
  385.  
  386. COPY <SOURCE Address> <DESTINATION Address> <LENGTH Length>
  387.  
  388. This  copies a section of the emulated address space from the source to the
  389. destination addresses.
  390.  
  391. SHOW [ASSEMBLER | DISASSEMBLER | SYMBOLS | REFERENCES | PARSE]
  392.  
  393. This  command  displays  the symbol table or unresolved references.  If the
  394. user specifies ASSEMBLER or DISASSEMBLER as the parameter then labels which
  395. were  generated  by  the  appropriate  module  are displayed, if SYMBOLS is
  396. defined   then  the  current  GLOBAL/EXTERNAL  symbols  are  displayed,  if
  397. REFERENCES is defined then the unresolved reference table is displayed.  If
  398. none  is  defined  then the symbol table is displayed in its entirety.  The
  399. number of entries in the symbol table is limited only by available memory.
  400. Defining the PARSE flag displays the parse tree of abstract instructions
  401. organised by the hashing function. At the end the number of entries and the
  402. maximum length of each hash table entry list is displayed. A maximum of 1
  403. indicates a 100% hit rate onto hashed abstract instructions.
  404.  
  405. INTERRUPTS [VALUE Value] [ON | OFF]
  406.  
  407. This  allows  the  user  to  control  the  system interrupts.  If the VALUE
  408. parameter  is  supplied  then  this  defines  the  number  of  Amiga  clock
  409. interrupts  to  receive  before  emulating  a Z80 interrupt.  If the ON/OFF
  410. parameter  is  defined then this controls overall system interrupts.  If it
  411. is  OFF  then the Z80 will never receive a clock interrupt.  Note that this
  412. has  nothing  to do with the status of interrupts on the Z80 (the IFF1 flag
  413. set  through  EI  and DI).  This is useful if you want to ignore interrupts
  414. completely  or are debugging a piece of code which involves interrupts, but
  415. you want to forget about them temporarily.  If no parameter is defined then
  416. the current settings are displayed.  Alternatively the interrupt status can
  417. be  changed  through  one  of  the Settings menu items.  Currently the only
  418. interrupts  supported  are  clock interrupts, as other devices have not yet
  419. been  implemented.   The  interrupt  system  should be identical to the Z80
  420. system;   allowing   for   all  three  interrupt  modes  and  maskable  and
  421. non-maskable  interrupts,  and priority interrupts.  I don't take advantage
  422. of this flexibility and completeness, but it will come into its own later.
  423.  
  424. EMULATE [8080 | Z80 | Zaphod]
  425.  
  426. This  command  defines  which system to emulate.  The Intel 8080 is not yet
  427. supported  (apart  from  the  downwards  compatability  of the Z80).  It is
  428. intended  to  add  assembly  and disassembly using the different opcodes of
  429. this  processor at some later stage.  Emulating a Z80 gives the user access
  430. to  the  CPU  and memory, but no I/O facilities.  Interrupts in this system
  431. respond by placing a value on the data bus (ie typically Interrupt Mode 0),
  432. which  is normally an RST instruction which defines the restart address for
  433. interrupt handling.
  434.  
  435. RUN [START Address] [TRACE] [SINGLESTEP] [PARSE]
  436.  
  437. Initiates  emulation at the specified address, or the current PC if none is
  438. defined.   Note  that  no commands affect the register contents, so that if
  439. the  user  breaks  out  of  emulation  and changes some contents of memory,
  440. simply  typing  RUN  will resume from where the emulation left off.  If the
  441. TRACE  parameter  is  defined  then the register contents are updated after
  442. every  instruction  (and dramatically reducing performance in the process).
  443. The  SINGLESTEP  parameter  defines that only a single instruction is to be
  444. emulated.  Useful in combination with the hot key for examining programs at
  445. a  pretty  low  level.  The user may press Escape at any stage to abort the
  446. emulation.   The  PARSE  flag  indicates that the program should build up a
  447. table  of  instructions  in  a pre-parsed, more easily recognisable format.
  448. Using  this  flag results in a throughput increase of about 25%, but at the
  449. cost of potentially high memory usage.
  450.  
  451. DEBUG [ON | OFF]
  452.  
  453. This  command  is a switch which causes some other commands to produce more
  454. output.   If  debugging is on the the assembler displays each line as it is
  455. processed,  together  with  the  bytes  to  which  it  was  assembled,  the
  456. disassembler  displays similar information (eg bytewise as well as mnemonic
  457. output),  and  the emulator will display the mnemonic of the instruction it
  458. is   currently   emulating  in  the  Ex:   box  in  the  register  display.
  459. Singlestepping   through   code   with   debugging  enabled  can  be  quite
  460. enlightening.   If  no  parameter  is defined then this command reports the
  461. current status, which may also be affected via one of the Settings menus.
  462.  
  463. DUMP <START Address> [END Address] [BINARY | OCTAL | DECIMAL | HEXADECIMAL]
  464.  
  465. Back  to  something a bit more simple.  A simple memory dump from the start
  466. address to the end address (if defined), or until the user presses Escape.
  467.  
  468. INITIALISE <START Address> <END Address | LENGTH Address> [VALUE Value]
  469.  
  470. Sets  every byte between the lower and upper bounds to the specified value.
  471. If the VALUE is not defined then 0 is assumed.
  472.  
  473. RESOLVE [REFERENCES]
  474.  
  475. This  explicitly tells the system to attempt to resolve any references that
  476. remain  unresolved after assembly.  Normally the user would define a couple
  477. labels or would assemble some other file with GLOBAL/EXTERNAL references to
  478. give  values  to these symbols.  The parameter may be defined for syntactic
  479. sugar but is not required.  The number of refernences that may be stored is
  480. limited only by available memory.
  481.  
  482. ROM [START Address] [END Address] [ON | OFF]
  483.  
  484. Declares the section of memory as Read Only.  Any updates inside this range
  485. will  have  no  effect.  The ROM may be enabled or disabled by the optional
  486. third  parameter.   If  the  START or END parameters are undefined then the
  487. current  values  are used.  Only one memory range can be defined as ROM for
  488. simplicity.
  489.  
  490. SCRIPT <FILE FileName>
  491.  
  492. Executes  the  script  with the specified name.  The script may contain any
  493. commands  or  instructions  that can be used in the system.  Therefore, you
  494. can  have  a  script  which  does  a whole bunch of things to customise the
  495. environment to your personal preferences.  On startup, the system looks for
  496. scripts  with the name Startup-Z80 in the current directory and in S:.  The
  497. scripts may even call other scripts if you want, get them to assemble files
  498. or  anything else you can normally do.  There is currently a built-in limit
  499. of 8 nested scripts.
  500.  
  501. COLOURS <Background> <Foreground> <Highlight> <Contrast>
  502.  
  503. This  command  allows  the  user  to  define  the colours to be used by the
  504. emulator.   Initially  the  program  will  use  the Workbench colours.  The
  505. easist  way  to define the colours is using hex notation eg.  COL $000 $FFF
  506. $F00 $00F
  507.  
  508. FONT [FONTNAME FontName] [SIZE FontSize]
  509.  
  510. This  program defines the font to be used by the program.  Chances are that
  511. your verions only supports the topaz 80 font.
  512.  
  513. ABOUT
  514.  
  515. Not particularly useful, just declares the author and version number.
  516.  
  517. HELP [MNEMONIC Mnemonic]
  518.  
  519. If  used  without  a  parameter  then the database of command structures is
  520. analysed  and  the  result displayed on the screen.  The assembler needs to
  521. store  a  database of valid commands for use when syntax checking, and this
  522. may  be interrogated to display valid operands for an instruction mnemonic.
  523. If you are unsure of the operand format for an instruction, or need to know
  524. which  instructions  are supported (eg undocumented instructions) then this
  525. database  will tell you as it is the same as used by the syntax checker and
  526. assembler.   Typing  HELP LD will give you all supported formats for the LD
  527. instruction.  In the list a 'r' denotes a single register, an 'n' denotes a
  528. single byte operand, 'nn' a word and 'd' a displacement byte.
  529.  
  530. QUIT
  531.  
  532. Exits the program.
  533.  
  534. In  addition  the  user  may type any valid instruction at the prompt which
  535. will  be  immediately emulated.  The instructions will have all the correct
  536. effects,  but  be  aware  that doing something like JP 1000 will do nothing
  537. more  than  set the PC to 1000 (ie the routine at 1000 will not continue to
  538. be  processed).  Of course following this up by singlestepping will achieve
  539. this.
  540.  
  541.  
  542. More about that Zaphod thing:
  543.  
  544. Having  a  Z80  is  all  very  well  but it's usually pretty nice to have a
  545. machine  to  do  something  with.  The modular approach to the system means
  546. that  new  machine  emulations  can  be added very quickly and easily, once
  547. their  specs  are  known.  If you have a pet system which you'd like to see
  548. incorporated  into the program then you need to do two things:  1.  Provide
  549. me with the specifications of the system, including such things as to which
  550. INput/OUTput  ports  it  responds  (which  port,  which  value),  interrupt
  551. behaviour,  memory mapping and anything else relevant, and 2.  wait a while
  552. (not  too  long  I  hope  but  I  can't guarantee anything).  I will try to
  553. incorporate requirements as best I can.
  554.  
  555. The Zaphod-1 emulation is a pretty simple emulation as it currently stands,
  556. mainly because I have done very little work on it.  When I devote more time
  557. to  it,  it  will gradually migrate towards responding to the complete VT52
  558. escape  sequences,  and  will  allow a greater range of device interaction,
  559. such as disk I/O.  If you request the Zaphod-1 mode, then a new medium-res,
  560. two-colour,  24x80 screen will be opened in the background.  When emulation
  561. is running, this console screen will be brought to the foreground, and when
  562. emulation is complete it will retire quietly into the background once more.
  563. This  screen  has  invisible gadgets in the top right corner.  The user may
  564. interact  with  the  console using standard IN and OUT instructions.  An IN
  565. from  port 0 will respond with the ASCII code of the last key pressed, or 0
  566. if none available.  An OUT to port 1 will display the appropriate character
  567. on  the  console  screen.   The  following  escape  sequences are currently
  568. supported:
  569.  
  570. ESC 0     - clears the console screen
  571. ESC 1 x y - moves the cursor position to x,y
  572. ESC 2     - clears to end of line from the current position
  573.  
  574. A quick code stub illustrates how to talk to Zaphod:
  575.  
  576.         ld c,1      ; Port 1 for output to console screen
  577.         ld a,27     ; ESC 0 clears the screen
  578.         out (C),a
  579.         ld a,0
  580.         out (c),a
  581.         ld c,0      ; Port 0 for input from the keyboard
  582. loop:   in a,(c)    ; IN with the C Indirect sets the flags
  583.         jr z,loop   ; make sure we have some input
  584.         out (1),a   ; output the result
  585.         jr loop     ; carry on
  586.  
  587. which  provides  a  simple teletype; whatever is typed at the keyboard will
  588. appear on the screen.  At some later stage I may write an OS around Zaphod;
  589. more likely he will develop into an emulation of some other system.
  590.  
  591. Undocumented Instructions:
  592.  
  593. The  basis  for the emulator has been the Z80 Assembly Language Programming
  594. Manual  written  by  Zilog.   I have therefore not implemented undocumented
  595. instructions  as, not surprisingly, I have no details on them.  There is no
  596. reason  why they shouldn't be implemented, however I will need the complete
  597. details first ie which flags are affected, any side effects.  I am aware of
  598. the  following  undocumented instructions, but would appreciate any further
  599. details on them or other instructions which are out there:
  600.  
  601. 1 - The byte Index register LD instructions.
  602.  
  603. Any  LD instruction which refers to the H or L registers may be prefixed by
  604. the  standard  index  extension  bytes DD and FD in which case instructions
  605. referring  to  H  will have be replaced by the high byte of the appropriate
  606. index  pair,  and  those  for  L by the low byte.  Other instructions which
  607. follow  this  pattern are:  ADC, ADD, AND, CP, DEC, INC, OR, SBC, SUB, XOR.
  608. If   anyone   can   give  me  suitably  acceptable  terminology  for  these
  609. instructions  (eg  LD  HX,B  for  load  High  byte  of  index into B) I may
  610. incorporate them.
  611.  
  612. 2 - The badly implemented Shifts and Rotates.
  613.  
  614. Analysis of the operand codes after the standard extend byte CB reveals the
  615. following pattern:
  616.  
  617. 00-07 RLC r     08-0F RRC r
  618. 10-17 RL r      18-1F RR r
  619. 20-27 SLA r     28-2F SRA r
  620. 30-37 ?????     38-3F SRL r
  621.  
  622. It  would  be  logical  to  assume  that  the  codes  30-37 should be SLL r
  623. instructions.   I  seem  to  remember  from a very long time ago that Zilog
  624. didn't  get  this quite right and got one of the shifted bits wrong, or the
  625. Carry  or something, and so didn't document the (quite predictable) effects
  626. of  the instructions as they didn't fall into the pattern.  Again, if I get
  627. some more details on these they may find their way into the emulator.
  628.  
  629. In particular this program owes itself to:
  630.  
  631. - Benchmark Modula 2 (Thanks Leon!), without which I would have had made
  632.   very many type incompatabilities.
  633.  
  634. - CygnusEd Professional, without which the development would have taken a
  635.   lot longer.
  636.  
  637. - Valeria and Pappagalla for keeping me amused from a distance.
  638.  
  639. - Bonnington for keeping me company late at night (this is my cat).
  640.  
  641. - Grolsch lager for lubricating my thought processes.
  642.  
  643. - Apple and cream pastry slices for maintaining my blood sugar levels.
  644.  
  645. - and of course the Commodore Amiga for being the best damn personal
  646.   computer available, without which I would have had to develop at
  647.   University, something not particularly high up on my list of enjoyable
  648.   evening pastimes!
  649.  
  650. Release history:
  651.  
  652. V1.00ß - 6th March 1992.
  653. Initial release.
  654.  
  655. V1.03 - 15th July 1992
  656. First non-beta release.
  657.  - Support for OS2.0 fonts
  658.  - Uses Workbench screen size and colours by default
  659.  - Works on NTSC systems!
  660.  - Preparsing of instructions
  661.  - Translation of memory image to 'C'
  662.  
  663. Having completed University, I have no more access to Internet etc. I can
  664. however be reached at:
  665.  
  666. 11 Oxford Court
  667. Ashley Road
  668. Epsom
  669. Surrey KT18 5BQ
  670. England
  671.  
  672. I'll respond to any queries I receive, and source is probably available upon
  673. request. You'll need a Modula-2 compiler (I use Benchmark) to make it all
  674. work. Thanks for using the program, hope it's not too frustrating.
  675.  
  676. Phil Brown.
  677.