jfrace.cpu
Class Intel8080

java.lang.Object
  |
  +--jfrace.cpu.Intel8080
All Implemented Interfaces:
AddressSpaceListener, CPU, Hardware
Direct Known Subclasses:
Z80

public class Intel8080
extends java.lang.Object
implements AddressSpaceListener, CPU

Emulation of the 8-bit microprocessor Intel 8080. The 256 port addresses are mapped as a block to the AddressSpace. The first address (i.e. the address of port 0) is defined by the method setPortBiasAddress.

In order to increase the performance of memory reading and writing the 65536 bytes of memory will not be accessed via the AddressSpace but directly on the byte array. This memory is obtained from the first RAM added to the AddressSpace.

Note: Currently interrupts are not supported. The method next returns always 1 and not the correct number of clock cycles.

Author:
Franz-Josef Elmer

Field Summary
static int A
          Index of register A (accumulator).
protected static short ACI
           
protected static short ADC
           
protected static short ADD
           
protected static int ADD_MASK
          Combined flag mask for ADD/SUB operations.
protected static short ADI
           
protected static short ANA
           
protected static short ANI
           
protected  AddressSpace as
           
static int AUX_CARRY_MASK
          Mask for the auxiliary carry flag.
static int AUX_CARRY_POS
          Bit position of the auxiliary carry flag.
static int B
          Index of register B.
static int C
          Index of register C.
protected static short CALL
           
static int CARRY_MASK
          Mask for the carry flag.
static int CARRY_POS
          Bit position of the carry flag.
protected static short Cc
           
protected static short CMA
           
protected static short CMC
           
protected static short CMP
           
protected static java.lang.String[] CONDITION_NAMES
           
protected static short CPI
           
static int D
          Index of register D.
protected static short DAA
           
protected static short DAD
           
protected static java.lang.String[] DATA_REGISTER_NAMES
           
protected static short DCR
           
protected static short DCX
           
protected static short DI
           
static int E
          Index of register E.
protected static short EI
           
protected  java.lang.String errorDescription
           
static int F
          Index of register F (flags).
static int H
          Index of register H.
protected static short HLT
           
protected static short IN
           
protected static short INR
           
protected static int INR_MASK
          Combined flag mask for INR/DCR operations.
protected  boolean interruptEnabled
           
protected static short INX
           
protected static short Jc
           
protected static short JMP
           
static int L
          Index of register L.
protected static short LDA
           
protected static short LDAX
           
protected static short LHLD
           
protected static short LXI
           
protected  byte[] memory
           
protected static short MOV
           
protected static short MVI
           
protected static short NOP
           
protected static byte NULL_BYTE
           
protected static short[] OP_CODE_TYPE
          Mapping op-code to instruction type.
protected static short ORA
           
protected static short ORI
           
protected static short OUT
           
static int PARITY_MASK
          Mask for the parity flag.
static int PARITY_POS
          Bit position of the parity flag.
static int PC
          Index of register PC (program counter).
protected static short PCHL
           
protected static short POP
           
protected  int portBiasAddress
           
protected  int programCounter
           
protected static short PUSH
           
protected static short RAL
           
protected static short RAR
           
protected static short Rc
           
protected static java.lang.String[] REGISTER_PAIR_NAMES
           
protected static java.lang.String[] REGISTER_PAIR_NAMES2
           
protected  byte[] registers
           
protected static short RET
           
protected static short RLC
           
protected static int ROT_MASK
          Combined flag mask for ROT operations.
protected static short RRC
           
protected static short RST
           
protected static short SBB
           
protected static short SBI
           
protected static short SHLD
           
static int SIGN_MASK
          Mask for the sign flag.
static int SIGN_POS
          Bit position of the sign flag.
static int SP
          Index of register SP (stack pointer).
protected static short SPHL
           
protected static short STA
           
protected  int stackPointer
           
protected static short STAX
           
protected static short STC
           
protected static short SUB
           
protected static short SUI
           
protected static short UDEF
           
protected static short XCHG
           
protected static short XRA
           
protected static short XRI
           
protected static short XTHL
           
static int ZERO_MASK
          Mask for the zero flag.
static int ZERO_POS
          Bit position of the zero flag.
 
Constructor Summary
Intel8080()
          Default constructor.
 
Method Summary
protected  void addToAccu(byte operand, int carry, int flagMask)
          Add operand and carry bit to accumulator and set the flags.
protected  int calculateParityFlag(int accu)
          Calculate the parity flag.
protected  boolean checkCondition(byte opCode)
          Check condition coded in the bits 3-5 of the op-code.
 int disassemble(java.lang.StringBuffer sb, int address)
          Return disassemble instruction in standard Intel 8080 assembler syntax.
protected  int disassembleByte(java.lang.StringBuffer sb, int address)
           
protected  int disassembleUDEF(byte opCode, java.lang.StringBuffer sb, int address)
           
protected  int disassembleWord(java.lang.StringBuffer sb, int address)
           
 AddressSpace getAddressSpace()
          Get the address space.
 java.lang.String getErrorDescription()
          Return error description.
 java.lang.String getName()
          Return "Intel 8080".
 int getNumberOfBits()
          Return 8.
 int getNumberOfRegisters()
          Return 10.
 int getPortBiasAddress()
          Return the bias address for ports.
 Register getProgramCounter()
          Return the program counter.
 Register getRegister(int index)
          Return a register.
protected  int getRegisterPair(byte opCode, boolean isPopPushPair)
          Get the value of a register pair.
protected  int getWord(int address)
          Obtain a 16-bit word from the memory.
 void hardwareMoved(AddressSpaceEvent event)
          When a RAM is added to the AddressSpace of the CPU the memory byte array is taken from it in order to improve reading/writing performance to the memory.
 void interrupt(long interrupt)
          Interrupts are not supported.
 int next()
          Proceed one opcode.
protected  int popFromStack()
          Pop a 16-bit word from the stack.
protected  boolean processHLT()
           
protected  boolean processINRorDCR(byte opCode, int increment)
          Process INR and DCR commands.
protected  boolean processUDEF(byte opCode)
          Process an undefined op-code.
protected  void pushOnStack(int word)
          Push a 16-bit word onto the stack.
protected  byte readByte(int address)
          Read the byte from a register or from memory.
 void reset()
          Reset the CPU.
protected  void setAccuAndFlags(int accu, int flags)
          Set accumulator and flags after a bit wise.
 void setAddressSpace(AddressSpace addressSpace)
          Set the address space.
 void setPortBiasAddress(int address)
          Set the bias address for ports.
protected  void setRegisterPair(byte opCode, int value, boolean isPopPushPair)
          Set the value of a register pair.
 void setRegisterValue(int index, int value)
          Set the value of a register.
protected  void storeByte(int address, byte value)
          Store a byte in a register or in memory.
protected  void subtractFromAccu(byte operand, int carry, int flagMask)
          Subtract operand and carry from accumulator and set the flags.
 boolean supportsDisassembling()
          Return true.
 java.lang.String toString()
          Show register states like CP/M DDT.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

A

public static final int A
Index of register A (accumulator).

F

public static final int F
Index of register F (flags).

B

public static final int B
Index of register B.

C

public static final int C
Index of register C.

D

public static final int D
Index of register D.

E

public static final int E
Index of register E.

H

public static final int H
Index of register H.

L

public static final int L
Index of register L.

SP

public static final int SP
Index of register SP (stack pointer).

PC

public static final int PC
Index of register PC (program counter).

SIGN_POS

public static final int SIGN_POS
Bit position of the sign flag.

ZERO_POS

public static final int ZERO_POS
Bit position of the zero flag.

AUX_CARRY_POS

public static final int AUX_CARRY_POS
Bit position of the auxiliary carry flag.

PARITY_POS

public static final int PARITY_POS
Bit position of the parity flag.

CARRY_POS

public static final int CARRY_POS
Bit position of the carry flag.

SIGN_MASK

public static final int SIGN_MASK
Mask for the sign flag.

ZERO_MASK

public static final int ZERO_MASK
Mask for the zero flag.

AUX_CARRY_MASK

public static final int AUX_CARRY_MASK
Mask for the auxiliary carry flag.

PARITY_MASK

public static final int PARITY_MASK
Mask for the parity flag.

CARRY_MASK

public static final int CARRY_MASK
Mask for the carry flag.

ADD_MASK

protected static final int ADD_MASK
Combined flag mask for ADD/SUB operations.

INR_MASK

protected static final int INR_MASK
Combined flag mask for INR/DCR operations.

ROT_MASK

protected static final int ROT_MASK
Combined flag mask for ROT operations.

DATA_REGISTER_NAMES

protected static final java.lang.String[] DATA_REGISTER_NAMES

REGISTER_PAIR_NAMES

protected static final java.lang.String[] REGISTER_PAIR_NAMES

REGISTER_PAIR_NAMES2

protected static final java.lang.String[] REGISTER_PAIR_NAMES2

CONDITION_NAMES

protected static final java.lang.String[] CONDITION_NAMES

UDEF

protected static final short UDEF

ACI

protected static final short ACI

ADC

protected static final short ADC

ADD

protected static final short ADD

ADI

protected static final short ADI

ANA

protected static final short ANA

ANI

protected static final short ANI

CALL

protected static final short CALL

Cc

protected static final short Cc

CMA

protected static final short CMA

CMC

protected static final short CMC

CMP

protected static final short CMP

CPI

protected static final short CPI

DAA

protected static final short DAA

DAD

protected static final short DAD

DCR

protected static final short DCR

DCX

protected static final short DCX

DI

protected static final short DI

EI

protected static final short EI

HLT

protected static final short HLT

IN

protected static final short IN

INR

protected static final short INR

INX

protected static final short INX

Jc

protected static final short Jc

JMP

protected static final short JMP

LDA

protected static final short LDA

LDAX

protected static final short LDAX

LHLD

protected static final short LHLD

LXI

protected static final short LXI

MOV

protected static final short MOV

MVI

protected static final short MVI

NOP

protected static final short NOP

ORA

protected static final short ORA

ORI

protected static final short ORI

OUT

protected static final short OUT

PCHL

protected static final short PCHL

POP

protected static final short POP

PUSH

protected static final short PUSH

RAL

protected static final short RAL

RAR

protected static final short RAR

Rc

protected static final short Rc

RET

protected static final short RET

RLC

protected static final short RLC

RRC

protected static final short RRC

RST

protected static final short RST

SBB

protected static final short SBB

SBI

protected static final short SBI

SHLD

protected static final short SHLD

SPHL

protected static final short SPHL

STA

protected static final short STA

STAX

protected static final short STAX

STC

protected static final short STC

SUB

protected static final short SUB

SUI

protected static final short SUI

XCHG

protected static final short XCHG

XRA

protected static final short XRA

XRI

protected static final short XRI

XTHL

protected static final short XTHL

OP_CODE_TYPE

protected static final short[] OP_CODE_TYPE
Mapping op-code to instruction type.

NULL_BYTE

protected static final byte NULL_BYTE

errorDescription

protected java.lang.String errorDescription

registers

protected byte[] registers

stackPointer

protected int stackPointer

programCounter

protected int programCounter

interruptEnabled

protected boolean interruptEnabled

as

protected AddressSpace as

memory

protected byte[] memory

portBiasAddress

protected int portBiasAddress
Constructor Detail

Intel8080

public Intel8080()
Default constructor.
Method Detail

getPortBiasAddress

public int getPortBiasAddress()
Return the bias address for ports. A 8080 port is mapped onto the address space where its address is the bias address plus the port number.

setPortBiasAddress

public void setPortBiasAddress(int address)
Set the bias address for ports. A 8080 port is mapped onto the address space where its address is the bias address plus the port number.
Parameters:
address - bias address.

toString

public java.lang.String toString()
Show register states like CP/M DDT.
Overrides:
toString in class java.lang.Object

processUDEF

protected boolean processUDEF(byte opCode)
Process an undefined op-code. Returns false. May be overwritten in subclasses.

processINRorDCR

protected boolean processINRorDCR(byte opCode,
                                  int increment)
Process INR and DCR commands.

processHLT

protected boolean processHLT()

disassembleUDEF

protected int disassembleUDEF(byte opCode,
                              java.lang.StringBuffer sb,
                              int address)

disassembleByte

protected int disassembleByte(java.lang.StringBuffer sb,
                              int address)

disassembleWord

protected int disassembleWord(java.lang.StringBuffer sb,
                              int address)

readByte

protected byte readByte(int address)
Read the byte from a register or from memory. The list shows the mapping between registers and address code:
RegisterAddress code
B0
C1
D2
E3
H4
L5
Memory6
A7
The memory address is given by the register pair HL.
Parameters:
address - address code.
Returns:
the read byte

storeByte

protected void storeByte(int address,
                         byte value)
Store a byte in a register or in memory. The list shows the mapping between registers and address code:
RegisterAddress code
B0
C1
D2
E3
H4
L5
Memory6
A7
The memory address is given by the register pair HL.
Parameters:
address - address code.
value - value to be stored.

getRegisterPair

protected int getRegisterPair(byte opCode,
                              boolean isPopPushPair)
Get the value of a register pair.
Op-code patternRegister pair
xx00xxxxBC
xx01xxxxDE
xx10xxxxHL
xx11xxxx AF if isPopPushPair == true
SP if isPopPushPair == false
Parameters:
opCode - op-code.
isPopPushPair - true if a register pair is meant for a POP or PUSH command.
Returns:
a word.

setRegisterPair

protected void setRegisterPair(byte opCode,
                               int value,
                               boolean isPopPushPair)
Set the value of a register pair.
Op-code patternRegister pair
xx00xxxxBC
xx01xxxxDE
xx10xxxxHL
xx11xxxx AF if isPopPushPair == true
SP if isPopPushPair == false
Parameters:
opCode - op-code.
value - value of the pair..
isPopPushPair - true if a register pair is meant for a POP or PUSH command.

getWord

protected int getWord(int address)
Obtain a 16-bit word from the memory. Assume lower order bit first.
Parameters:
address - memory address.
Returns:
word.

pushOnStack

protected void pushOnStack(int word)
Push a 16-bit word onto the stack. The high byte will be stored in stackPointer - 1 and the low byte in stackPointer - 2. The stack pointer will be decreased by two.
Parameters:
word - word to be push onto the stack.

popFromStack

protected int popFromStack()
Pop a 16-bit word from the stack. The low byte will be read from stackPointer and the high byte in stackPointer + 1. The stack pointer will be increased by two.
Returns:
poped word.

checkCondition

protected boolean checkCondition(byte opCode)
Check condition coded in the bits 3-5 of the op-code.
Op-code patternCondition
xx000xxx NZ zeroFlag == false
xx001xxx Z zeroFlag == true
xx010xxx NC carryFlag == false
xx011xxx C carryFlag == true
xx100xxx PO parityFlag == false
xx101xxx PE parityFlag == true
xx110xxx P signFlag == false
xx111xxx M signFlag == true
Parameters:
opCode - op-code.
Returns:
true if the condition is fulfilled.

addToAccu

protected void addToAccu(byte operand,
                         int carry,
                         int flagMask)
Add operand and carry bit to accumulator and set the flags.

subtractFromAccu

protected void subtractFromAccu(byte operand,
                                int carry,
                                int flagMask)
Subtract operand and carry from accumulator and set the flags.

setAccuAndFlags

protected void setAccuAndFlags(int accu,
                               int flags)
Set accumulator and flags after a bit wise.
Parameters:
accu - result of the bit wise operation.
flags - initial flags set.

calculateParityFlag

protected int calculateParityFlag(int accu)
Calculate the parity flag. Return PARITY_MASK if there is an even number of bits set in the lowest order byte of accu.
Returns:
PARITY_MASK if an even number bits of the accumulator have the value 1. Otherwise 0 is returned.

hardwareMoved

public void hardwareMoved(AddressSpaceEvent event)
When a RAM is added to the AddressSpace of the CPU the memory byte array is taken from it in order to improve reading/writing performance to the memory.
Specified by:
hardwareMoved in interface AddressSpaceListener
Following copied from interface: jfrace.AddressSpaceListener
Parameters:
event - Event holding the details.

getName

public java.lang.String getName()
Return "Intel 8080".
Specified by:
getName in interface CPU

getNumberOfBits

public int getNumberOfBits()
Return 8.
Specified by:
getNumberOfBits in interface Hardware

getNumberOfRegisters

public int getNumberOfRegisters()
Return 10.
Specified by:
getNumberOfRegisters in interface CPU

getRegister

public Register getRegister(int index)
Description copied from interface: CPU
Return a register.
Specified by:
getRegister in interface CPU
Following copied from interface: jfrace.CPU
Parameters:
index - Index of the register.
Returns:
null if no register exists for the given index.

getProgramCounter

public Register getProgramCounter()
Description copied from interface: CPU
Return the program counter. The program counter is a special register.
Specified by:
getProgramCounter in interface CPU

setRegisterValue

public void setRegisterValue(int index,
                             int value)
Description copied from interface: CPU
Set the value of a register.
Specified by:
setRegisterValue in interface CPU
Following copied from interface: jfrace.CPU
Parameters:
index - Index of the register.
value - New value.

setAddressSpace

public void setAddressSpace(AddressSpace addressSpace)
Set the address space. Looks for already existing RAM. If one found it takes the corresponding memory array.
Specified by:
setAddressSpace in interface CPU

getAddressSpace

public AddressSpace getAddressSpace()
Description copied from interface: CPU
Get the address space.
Specified by:
getAddressSpace in interface CPU

reset

public void reset()
Reset the CPU. The internal state will be set into a well-defined initial state.
Specified by:
reset in interface Hardware

interrupt

public void interrupt(long interrupt)
Interrupts are not supported.
Specified by:
interrupt in interface CPU
Following copied from interface: jfrace.CPU
Parameters:
interrupt - Bit pattern of the interrupt. The meaning of the bits depend on the implementation.

getErrorDescription

public java.lang.String getErrorDescription()
Return error description. The meaning of the error code depends on the implementation. This method should be called when next() return false.
Specified by:
getErrorDescription in interface CPU
Returns:
an empty string if no error occured.

next

public int next()
Proceed one opcode.
Specified by:
next in interface CPU
Returns:
always 1 excepted in the case of an error.

supportsDisassembling

public boolean supportsDisassembling()
Return true.
Specified by:
supportsDisassembling in interface CPU

disassemble

public int disassemble(java.lang.StringBuffer sb,
                       int address)
Return disassemble instruction in standard Intel 8080 assembler syntax.
Specified by:
disassemble in interface CPU
Following copied from interface: jfrace.CPU
Parameters:
sb - String buffer.
address - Address of op-code.
Returns:
number of addressable units of the op-code at address.