home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / Z80 emulator / 68K version / Z80.68k.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-01  |  2.9 KB  |  101 lines  |  [TEXT/CWIE]

  1.  
  2. /*    Z80 Emulator
  3.     Copyright (C) 1994 G.Woigk
  4.     
  5.     This file is part of Mac Spectacle and it is free software
  6.     See application.c for details
  7.             
  8.     This program is distributed in the hope that it will be useful,
  9.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
  11.  
  12.     01.Mai.94     Started work on this file                    KIO !
  13.     11.Dec.94     Now preserving all bits with push/pop AF        KIO !
  14.     18.Jan.95     Improved interrupt dispatcher                KIO !
  15.     22.Jan.95     Trace mode                            KIO !
  16.     28.Jan.95     CMD_PROFILE                            KIO !
  17.     05.Mar.95    full r-register emulation                    KIO !
  18.     12.Mar.95    T cycle counter                            KIO !
  19.     17.Mar.95    revised exception handling of Z80()            KIO !
  20.     23.Mar.95    now always including both Z80() and Z80_T()    KIO !
  21.     29.Mrz.95     Separated this file from Init_Z80.c            KIO !
  22.     10.Apr.95     ROM write protection                    KIO !
  23. */
  24.  
  25.  
  26. #include     <AppleEvents.h>
  27. #include    <quickdraw.h>
  28.  
  29. #include    "kio.h"
  30. #include    "z80.h"
  31. #include    "application.h"
  32. #include    "display.h"
  33. #include    "console.h"
  34.  
  35. #include    "z80.options"
  36. #include    "z80.macros"
  37.  
  38.  
  39. /* -----    The Z80 engine ----------------------------------------------------------
  40.  
  41.     There are two versions:
  42.     •  Z80():        exact_timing = rom_protection = false
  43.                 no T cycle counting; no ROM write protection; fastest; 
  44.                 no timing-loop depending sound, tape i/o etc. possible
  45.     •  Z80_T():    exact_timing = rom_protection = true
  46.                 T cycle counting; ROM write protection; 40% slower; 
  47.                 Do-Cycles() is used; timing loop depending sound, tape i/o possible
  48.  
  49.     On entry/return some registers are loaded from and written back to 'zreg'
  50.  
  51.     WUFF (irpt and nmi flags) is tested
  52.     •  on entry of Z80()
  53.     •  after ei instruction
  54.     •  Z80_T():    after Do_Cycles() after CYCLES reached 0 and EXIT is not set 
  55.     
  56.     EXIT (watchdog) and WUFF (nmi/irpt) are tested
  57.     •  Z80_T():    Do_Cycles() is called after CYCLES reaches 0
  58.                 after Do_Cycles() returns, EXIT and WUFF are tested
  59.     •  Z80():        after every bra/jp/call/ret/rst
  60.  
  61.     Single instructions may be executed by calling Z80_T() with CYCLES=4
  62.     Then one of the following is processed: (in priority order)
  63.     •  handle nmi request
  64.     •  handle irpt request (if interrupts are enabled)
  65.     •  execute one instruction, except:
  66.     •  if instruction is EI, handle EI and next instruction in one go
  67.  
  68.     If Z80() returns, it's result value indicates one of the following conditions:
  69.     •  not supported instruction at zreg.IP
  70.     •  rst0 instruction at zreg.IP-1
  71.     •  halt instruction at zreg.IP-1
  72.     •  EXIT set
  73. */
  74.  
  75.  
  76. // -----    Fastest interpreter: no T cycle counting, no ROM write protection ---------------
  77. #define    exact_timing    false
  78. #define    rom_protection    false
  79. #define    exact_bit        false
  80. #define    exact_xy_bit    false
  81.  
  82. short asm Z80 ( )
  83. {
  84. #include    "Z80_proc.c"
  85. }
  86.  
  87.  
  88. // -----    T cycle counting and ROM write protection ------------------------------
  89. #define    exact_timing    true
  90. #define    rom_protection    true
  91. #define    exact_bit        true
  92. #define    exact_xy_bit    false
  93.  
  94. asm short Z80_T ( )
  95. {
  96. #include    "Z80_proc.c"
  97. }
  98.  
  99.  
  100.  
  101.