ca.disassembly.invaders
Class Z80

java.lang.Object
  extended by ca.disassembly.invaders.Z80
Direct Known Subclasses:
InvadersMachine

public class Z80
extends java.lang.Object

CPUZ80 emulates a Z80's behaviour Written in 2001 by E.Duijs as a part of JEmu V1.00 + Many programs run ok. + removed generic parsing by big switch/case blocks for better performance + made functions for many instructions and flags + added NMI - IM0 not ok yet (is now always RST 38) - some missing instructions - DAA not ok, probably due to missing/incorrect half-carry updates V1.1 + IM0 now also supports calls to other locations (other than 0x38) + DAA is corrected + Fixed many flagupdates + An interface 'driver' is passed to exec() instead of a class. Makes it more flexible. + Implements interface 'cpu'. - IM0 doesn't support instructions other than calls, but this is no big deal... - still some missing instructions - code needs to be cleaned up - debugger needs to be finished (mainly the opcode tables). - out & in need to be externalized (it's added in interface 'driver' already) V1.2 + Flag calculations are not done in F anymore but all flags are booleans (faster) + 1 Minor bugfix... V1.3 + Added precalculated flag tables for speed. + Removed the boolean representation for flags. + The flag arrays also fixed some issues that were apparently flag related. + Added some missing instructions. - Because of the flag tables, it takes more memory now. V1.4 + Added INI and IND opcodes V1.41 + Removed localization of PC from fetch-decode loop to support protection in for example Scramble. I'll probably remove localization of all registers later. It was a speed optimization, but the result is only a very minor speedup. Also, it makes further optimizations difficult if not impossible. V1.42 + Fixed LD D,HX / LD D,LX / LD D,HY / LD D,LY V1.5 + Restructured fetch/decode/exec loop so that it performs better on Sun JRE (HotSpot didn't compile exec() at all). + Better maintainable + Fixed one index instruction.


Field Summary
 int A
           
 int A1
           
 int B
           
 int B1
           
 int C
           
 int C1
           
 int cycle
           
 int cycleCounter
           
 int D
           
 int D1
           
 int E
           
 int E1
           
 int F
           
 int F1
           
 int H
           
 int H1
           
 int I
           
 int I_Vector
           
 boolean IFF0
           
 boolean IFF1
           
 int IM
           
static int IM0
           
static int IM1
           
static int IM2
           
static int INTERRUPT_TYPE_FIRQ
          Interrupt type
static int INTERRUPT_TYPE_IGNORE
          Interrupt type
static int INTERRUPT_TYPE_IRQ
          Interrupt type
static int INTERRUPT_TYPE_NMI
          Interrupt type
 boolean IRQ
           
 int IX
           
 int IXYd
           
 int IY
           
 int L
           
 int L1
           
 boolean NMI
           
static java.lang.String[] opc1
           
static java.lang.String[] opc2
           
static java.lang.String[] opc3
           
 int PC
           
static int PROPERTY_Z80_IRQ_VECTOR
          Property type
 int R
           
 int SP
           
 boolean state_HALT
           
 
Constructor Summary
Z80()
          Default constructor debugging disabled Use this constructor for use in applets
 
Method Summary
 void AF(int nn)
           
 void BC(int nn)
           
 void DE(int nn)
           
 void ex_AF_AF()
          EX AF,AF'
 void exec(int cycles)
          Execute a number of clock cycles
 void exx()
          EXX
 int getCycle()
           
 long getInstruction()
          returns the currently excecuted instruction
 int getPC()
          returns the program counter register (PC)
 java.lang.String getTag()
           
 void HL(int nn)
           
 int inb(int port, int hi)
           
 void interrupt(int type, boolean irq)
           
 void irq()
          irq request
 void IX(int nn)
           
 void IY(int nn)
           
 void nmi()
          Non-Maskable irq request
 void outb(int port, int value, int status)
           
 int peekb(int add)
           
 int peekw(int add)
           
 void pokeb(int add, int value)
           
 void pokew(int add, int value)
           
 int pop()
           
 void reset()
          Reset CPU - Only resets the registers
 void setDebug(boolean debug)
           
 void setProperty(int property, int value)
           
 void setTag(java.lang.String tag)
           
 void step()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IM0

public static final int IM0
See Also:
Constant Field Values

IM1

public static final int IM1
See Also:
Constant Field Values

IM2

public static final int IM2
See Also:
Constant Field Values

INTERRUPT_TYPE_IRQ

public static final int INTERRUPT_TYPE_IRQ
Interrupt type

See Also:
Constant Field Values

INTERRUPT_TYPE_NMI

public static final int INTERRUPT_TYPE_NMI
Interrupt type

See Also:
Constant Field Values

INTERRUPT_TYPE_FIRQ

public static final int INTERRUPT_TYPE_FIRQ
Interrupt type

See Also:
Constant Field Values

INTERRUPT_TYPE_IGNORE

public static final int INTERRUPT_TYPE_IGNORE
Interrupt type

See Also:
Constant Field Values

PROPERTY_Z80_IRQ_VECTOR

public static final int PROPERTY_Z80_IRQ_VECTOR
Property type

See Also:
Constant Field Values

A

public int A

F

public int F

B

public int B

C

public int C

D

public int D

E

public int E

H

public int H

L

public int L

I

public int I

R

public int R

A1

public int A1

F1

public int F1

B1

public int B1

C1

public int C1

D1

public int D1

E1

public int E1

H1

public int H1

L1

public int L1

PC

public int PC

SP

public int SP

IX

public int IX

IY

public int IY

IXYd

public int IXYd

state_HALT

public boolean state_HALT

IM

public int IM

IFF0

public boolean IFF0

IFF1

public boolean IFF1

I_Vector

public int I_Vector

IRQ

public boolean IRQ

NMI

public boolean NMI

cycle

public int cycle

cycleCounter

public int cycleCounter

opc1

public static final java.lang.String[] opc1

opc2

public static final java.lang.String[] opc2

opc3

public static final java.lang.String[] opc3
Constructor Detail

Z80

public Z80()
Default constructor debugging disabled Use this constructor for use in applets

Method Detail

setTag

public void setTag(java.lang.String tag)

getTag

public java.lang.String getTag()

getInstruction

public final long getInstruction()
returns the currently excecuted instruction


interrupt

public final void interrupt(int type,
                            boolean irq)

getPC

public final int getPC()
returns the program counter register (PC)


setDebug

public final void setDebug(boolean debug)

setProperty

public final void setProperty(int property,
                              int value)

irq

public final void irq()
irq request


nmi

public final void nmi()
Non-Maskable irq request


reset

public final void reset()
Reset CPU - Only resets the registers


getCycle

public final int getCycle()

step

public void step()

exec

public final void exec(int cycles)
Execute a number of clock cycles

Parameters:
cycles - number of cycles to be excecuted

ex_AF_AF

public final void ex_AF_AF()
EX AF,AF'


exx

public final void exx()
EXX


AF

public final void AF(int nn)

BC

public final void BC(int nn)

DE

public final void DE(int nn)

IX

public final void IX(int nn)

IY

public final void IY(int nn)

HL

public final void HL(int nn)

pop

public final int pop()

outb

public void outb(int port,
                 int value,
                 int status)

inb

public int inb(int port,
               int hi)

peekb

public int peekb(int add)

pokeb

public void pokeb(int add,
                  int value)

peekw

public int peekw(int add)

pokew

public void pokew(int add,
                  int value)