jmce - 1_02

jmce.intel.mcs51
Class MCS51

java.lang.Object
  extended by jmce.sim.AbstractHardware
      extended by jmce.sim.cpu.AbstractCPU
          extended by jmce.intel.mcs51.MCS51
All Implemented Interfaces:
java.lang.Runnable, MCS51Constants, BreakPointListener, CPU, Hardware, InterruptManager
Direct Known Subclasses:
LPC764, MCS52

public class MCS51
extends AbstractCPU
implements MCS51Constants

Implementation of Intel MCS51.

Supported memory :

Memory addressing

The Intel 8051 have a unique 8 bit data memory addressing : When accessed in indirect mode always the DATA memory is referenced, when accessed in direct mode the first 128 byte reference the DATA memory the other 128 byte (Location from 128 to 255) reference the SFR memory.

Implemented peripheral :

This class is derived form a previus 8051 emulator and the simulation very well tested.

This CPU honor the AbstractCPU.setCallListener(int, jmce.sim.CallListener) method.

Version:
1.05
Author:
Mario Viara

Field Summary
static java.lang.String CODE_MEMORY
          Code memory name
static java.lang.String DATA_MEMORY
          Data memory name
protected static Logger log
           
static java.lang.String SFR_MEMORY
          Special function register memory name
static java.lang.String XDATA_MEMORY
          External data memory name
 
Fields inherited from class jmce.sim.cpu.AbstractCPU
interrupts, io, memory, NS100MS, NS1MS
 
Fields inherited from interface jmce.intel.mcs51.MCS51Constants
ACC, AUXR1, B, DPH, DPL, IE, IE_EA, IE_EC, IE_ES, IE_ET0, IE_ET1, IE_ET2, IE_EX0, IE_EX1, P0, P0M1, P0M2, P1, P1M1, P1M2, P2, P2M1, P2M2, P3, P3M1, P3M2, PSW, PSW_AC, PSW_CY, PSW_F0, PSW_F1, PSW_OV, PSW_P, PSW_RS0, PSW_RS1, SBUF, SCON, SCON_RI, SCON_TI, SP, TCON, TCON_TF0, TCON_TF1, TCON_TR0, TCON_TR1, TH0, TH1, TL0, TL1, TMOD, TMOD_C_T0, TMOD_C_T1, TMOD_GATE0, TMOD_GATE1, TMOD_T0_M0, TMOD_T0_M1, TMOD_T1_M0, TMOD_T1_M1
 
Fields inherited from interface jmce.sim.CPU
BIG_ENDIAN, IO_MEMORY, LITTLE_ENDIAN, MAIN_MEMORY
 
Constructor Summary
MCS51()
          Default constructor
 
Method Summary
 boolean ac()
           
 void ac(boolean value)
           
protected  int acc()
          Return the value of the accumulator.
protected  void acc(int value)
          Set the accumulator.
 void addSfrReadListener(int a, MemoryReadListener l)
          Deprecated. Use addIOReadListener
 void addSfrWriteListener(int address, MemoryWriteListener l)
          Deprecated. Use addIOWriteListener
 int code(int addr)
          Return byte from the code memory.
 void code(int addr, int value)
           
 int code16(int addr)
          Return a word from the code memory.
 void cplBit(int bit)
          Complement bit
 boolean cy()
           
 void cy(boolean value)
           
 int data(int add)
           
 void data(int add, int value)
           
 int fireISR(Interrupt isr)
          This function must be overridden from sub class that implements interrupt.
 boolean getBit(int add)
          Return a bit
 boolean getBitCode(int add)
           
 java.lang.String getBitName(int add)
          Return a bit name
protected  Memory getData()
          Return the memory used as DATA
protected  java.lang.String getDataName(int r)
          Return a name for DATA address space.
 int getDirect(int add)
          Get a directy byte of memory.
protected  int getDirectCode(int pc)
           
 java.lang.String getDirectName(int add)
          Return the name of a direct byte of memory.
 int getDptr(int i)
          Return the DPTR register with the specified index
protected  Memory getSfr()
          Return the memory used as SFR.
 MemoryBit getSfrBit(int address, int bit)
           
 OpenCollectorMemoryBit getSfrBitOpenCollector(int address, int bit)
           
protected  java.lang.String getSfrName(int address)
          Return a name for SFR address space
 int getWord(int a)
          Read one word (16 bit) from the main memory.
protected  Memory getXdata()
          Return the memory used as XDATA
protected  int getXdataHi()
          Return the 8 high bit during 8 bit access to XDATA
 void init(Hardware parent)
          Initialize the hardware.
protected  void initListeners()
          Add all required memory listeners
protected  void initMemories()
          Initialize the memories.
protected  void initNames()
           
protected  void initOpcodeDecoder()
           
protected  void initOpcodes()
          Initialize the opcodes.
protected  void initPeripherals()
          Initialize peripherals.
protected  void initRegisters()
          Initialize the register.
 boolean isInterruptEnabled()
          Return the status of the interrupt enable
 boolean ov()
           
 void ov(boolean value)
           
 int pc()
          Return the register used as program counter
 void pc(int pc)
          Set the program counter.
 int pop()
          Pop a byte from the stack
 int popw()
          Pop a word from the stack.
 int psw()
          Return the PSW.
 void psw(int value)
          Set the PSW.
 void push(int value)
          Push a byte in to the stack.
 void pushw(int value)
          Push a word in to the stack.
protected  int r(int r)
           
protected  void r(int r, int n)
           
 void reset()
          Reset the CPU and call all installed ResetListener.
protected  void setAuxrDptrEnabled()
          Enabled the standard AUXR1 dptr.
 void setBit(int add, boolean value)
          Set a bit
 void setBitName(int add, java.lang.String name)
          Set a bit name
protected  void setData(Memory m)
          Set the memory used as DATA
protected  void setDataName(int r, java.lang.String name)
          Set the name for DATA address space.
 void setDirect(int add, int value)
          Set a directy byte of memory.
 void setDptrIndex(int i)
          Set the current DPTR index
protected  void setSfr(Memory m)
          Setr the memory used as SFR.
 void setSfrBitmap(int i, int add)
          Set the internal address of one bit
protected  void setSfrName(int address, java.lang.String name)
          Set a name for SFR address space.
protected  void setSfrXdataHi(int sfr)
           
 void setWord(int a, int v)
          Set one word (16 bit) in the main memory
protected  void setXdata(Memory m)
          Set the memory used aas XDATA
 int sfr(int add)
          Return a SFR register.
 void sfr(int add, int value)
          Set a SFR.
 boolean sfrIsBit(int add, int mask)
           
 void sfrReset(int sfr, int mask)
          Reset bits in the the SFR memory.
 void sfrSet(int sfr, int mask)
          Set bit in the SFR MEMORY.
 void sfrSetBit(int add, int mask)
           
 int xdata(int add)
           
 void xdata(int add, int value)
           
 
Methods inherited from class jmce.sim.cpu.AbstractCPU
abort, addCycleListener, addDecoder, addExceptionListener, addExecBreakPoint, addInterrupt, addIOReadListener, addIOReadListener, addIOWriteListener, addIOWriteListener, addLoader, addMemoryWriteListener, addOffset, addReadBreakPoint, addRegister, addResetListener, addTimerCycle, addTimerMs, addTraceListener, addWriteBreakPoint, bit0, bit7, breakPointEvent, createRuntime, decodeAt, destroy, dumpStatistics, dumpStatistics, dumpTitle, dumpValue, dumpValue, fetch, fireNMI, formatFrequence, getBreakPointAt, getBreakPointCount, getByte, getCallListener, getClock, getClockPerCycle, getCycle, getCycleMillis, getDecoderAt, getDecoderCount, getEndian, getExceptionListenerAt, getExceptionListenerCount, getExecStatistics, getInterruptCount, getInterruptCounter, getInterruptName, getIOByte, getLenghtAt, getMemory, getMemoryAt, getMemoryCount, getMemoryForName, getOpcodeAt, getOpcodes, getRealTime, getRegisterAt, getRegisterCount, getRegisterForName, getResetAddress, getUsage, getUsageDesc, getWordBig, getWordLittle, halt, idle, isBigEndian, isLittleEndian, isRunning, load, load, notifyInterrupt, removeBreakPoint, removeBreakPoint, removeExceptionListener, removeTraceListener, resetRegisters, run, run0, setByte, setCallListener, setClock, setClockPerCycle, setEndian, setIO, setIOByte, setMemory, setOpcode, setRealTime, setResetAddress, setStatusLine, setTill, start, step, step0, stepNoBreak, stop
 
Methods inherited from class jmce.sim.AbstractHardware
addHardware, createFrame, getHardware, getHardware, getHardware, getHardware, getHardware, getHardwareCount, getHardwareForName, getHardwareInstances, getHardwareTree, getName, getParent, initSwing, removeHardware, removeHardware, setHardware, setHardware, setName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface jmce.sim.Hardware
addHardware, getHardware, getHardware, getHardware, getHardware, getHardwareCount, getHardwareInstances, getHardwareTree, getName, getParent, initSwing, removeHardware, removeHardware, setHardware, setHardware, setName
 

Field Detail

log

protected static final Logger log

CODE_MEMORY

public static final java.lang.String CODE_MEMORY
Code memory name

See Also:
Constant Field Values

XDATA_MEMORY

public static final java.lang.String XDATA_MEMORY
External data memory name

See Also:
Constant Field Values

DATA_MEMORY

public static final java.lang.String DATA_MEMORY
Data memory name

See Also:
Constant Field Values

SFR_MEMORY

public static final java.lang.String SFR_MEMORY
Special function register memory name

See Also:
Constant Field Values
Constructor Detail

MCS51

public MCS51()
Default constructor

Method Detail

setWord

public final void setWord(int a,
                          int v)
                   throws SIMException
Description copied from interface: CPU
Set one word (16 bit) in the main memory

Specified by:
setWord in interface CPU
Parameters:
a - - Address
v - - value
Throws:
SIMException

getWord

public final int getWord(int a)
                  throws SIMException
Description copied from interface: CPU
Read one word (16 bit) from the main memory.

Specified by:
getWord in interface CPU
Parameters:
a - - Address
Returns:
The word at the specified address.
Throws:
SIMException

getXdataHi

protected int getXdataHi()
                  throws SIMException
Return the 8 high bit during 8 bit access to XDATA

Throws:
SIMException

setSfrXdataHi

protected void setSfrXdataHi(int sfr)

getXdata

protected Memory getXdata()
Return the memory used as XDATA


getSfr

protected Memory getSfr()
Return the memory used as SFR.


setSfr

protected void setSfr(Memory m)
Setr the memory used as SFR.


setXdata

protected void setXdata(Memory m)
Set the memory used aas XDATA


getData

protected Memory getData()
Return the memory used as DATA


setData

protected void setData(Memory m)
Set the memory used as DATA


sfr

public final int sfr(int add)
              throws SIMException
Return a SFR register.

Throws:
SIMException

sfr

public final void sfr(int add,
                      int value)
               throws SIMException
Set a SFR.

Throws:
SIMException

getDirect

public final int getDirect(int add)
                    throws SIMException
Get a directy byte of memory.

The first 128 location (0..127) reference DATA memory the last (128 .. 255) the SFR memory.

Parameters:
add - - Address 0 .. 255
Returns:
the result.
Throws:
SIMException

setDirect

public final void setDirect(int add,
                            int value)
                     throws SIMException
Set a directy byte of memory.

The first 128 location (0..127) reference DATA memory the last (128 .. 255) the SFR memory.

Parameters:
add - - Address 0 .. 255
Throws:
SIMException

getDirectName

public java.lang.String getDirectName(int add)
Return the name of a direct byte of memory.

The first 128 location (0..127) reference DATA memory the last (128 .. 255) the SFR memory.

Parameters:
add - - Address 0 .. 255

getBitCode

public final boolean getBitCode(int add)
                         throws SIMException
Throws:
SIMException

getDirectCode

protected final int getDirectCode(int pc)
                           throws SIMException
Throws:
SIMException

initOpcodes

protected void initOpcodes()
Initialize the opcodes.


setBitName

public void setBitName(int add,
                       java.lang.String name)
Set a bit name


getBitName

public java.lang.String getBitName(int add)
Return a bit name


setSfrBitmap

public void setSfrBitmap(int i,
                         int add)
Set the internal address of one bit


getBit

public final boolean getBit(int add)
                     throws SIMException
Return a bit

Throws:
SIMException

cplBit

public final void cplBit(int bit)
                  throws SIMException
Complement bit

Throws:
SIMException

setBit

public final void setBit(int add,
                         boolean value)
                  throws SIMException
Set a bit

Throws:
SIMException

initRegisters

protected void initRegisters()
Initialize the register.


setDataName

protected void setDataName(int r,
                           java.lang.String name)
Set the name for DATA address space.


getDataName

protected java.lang.String getDataName(int r)
Return a name for DATA address space.


setSfrName

protected void setSfrName(int address,
                          java.lang.String name)
Set a name for SFR address space.


getSfrName

protected java.lang.String getSfrName(int address)
Return a name for SFR address space


initMemories

protected void initMemories()
Initialize the memories.


initNames

protected void initNames()

initOpcodeDecoder

protected void initOpcodeDecoder()

initPeripherals

protected void initPeripherals()
                        throws SIMException
Initialize peripherals.

Throws:
SIMException

initListeners

protected void initListeners()
                      throws SIMException
Add all required memory listeners

Throws:
SIMException
Since:
1.02

isInterruptEnabled

public final boolean isInterruptEnabled()
Description copied from interface: CPU
Return the status of the interrupt enable

Specified by:
isInterruptEnabled in interface CPU

init

public void init(Hardware parent)
          throws SIMException
Description copied from interface: Hardware
Initialize the hardware. This method must be called before any use of the interface. Only set ... / get ... method are allowed to be called before the intialization.

Specified by:
init in interface Hardware
Overrides:
init in class AbstractCPU
Parameters:
parent - Parent of this hardware.
Throws:
SIMException

sfrReset

public void sfrReset(int sfr,
                     int mask)
              throws SIMException
Reset bits in the the SFR memory.

Parameters:
sfr - - Address.
mask - - Bit to reset.
Throws:
SIMException

sfrSet

public void sfrSet(int sfr,
                   int mask)
            throws SIMException
Set bit in the SFR MEMORY.

Parameters:
sfr - - Address.
mask - - Bit(s) to set.
Throws:
SIMException

getSfrBitOpenCollector

public OpenCollectorMemoryBit getSfrBitOpenCollector(int address,
                                                     int bit)

getSfrBit

public MemoryBit getSfrBit(int address,
                           int bit)

addSfrReadListener

@Deprecated
public void addSfrReadListener(int a,
                                          MemoryReadListener l)
Deprecated. Use addIOReadListener

Add a memory read listener to the SFR memory


addSfrWriteListener

@Deprecated
public void addSfrWriteListener(int address,
                                           MemoryWriteListener l)
Deprecated. Use addIOWriteListener

Add a memory write listener to the SFR memory.


pc

public final void pc(int pc)
              throws SIMException
Description copied from interface: CPU
Set the program counter.

Specified by:
pc in interface CPU
Parameters:
pc - - New value for the program counter.
Throws:
SIMException

pc

public final int pc()
             throws SIMException
Description copied from interface: CPU
Return the register used as program counter

Specified by:
pc in interface CPU
Returns:
- Program counter.
Throws:
SIMException

r

protected final int r(int r)
               throws SIMException
Throws:
SIMException

r

protected final void r(int r,
                       int n)
                throws SIMException
Throws:
SIMException

code

public void code(int addr,
                 int value)
          throws SIMException
Throws:
SIMException

acc

protected final int acc()
                 throws SIMException
Return the value of the accumulator.

Throws:
SIMException

acc

protected final void acc(int value)
                  throws SIMException
Set the accumulator.

Throws:
SIMException

psw

public final int psw()
              throws SIMException
Return the PSW.

Throws:
SIMException

psw

public final void psw(int value)
               throws SIMException
Set the PSW.

Throws:
SIMException

cy

public final void cy(boolean value)
              throws SIMException
Throws:
SIMException

cy

public final boolean cy()
                 throws SIMException
Throws:
SIMException

ac

public final void ac(boolean value)
              throws SIMException
Throws:
SIMException

ac

public final boolean ac()
                 throws SIMException
Throws:
SIMException

ov

public final void ov(boolean value)
              throws SIMException
Throws:
SIMException

ov

public final boolean ov()
                 throws SIMException
Throws:
SIMException

code

public final int code(int addr)
               throws SIMException
Return byte from the code memory.

Throws:
SIMException

code16

public final int code16(int addr)
                 throws SIMException
Return a word from the code memory.

Throws:
SIMException

xdata

public final int xdata(int add)
                throws SIMException
Throws:
SIMException

xdata

public final void xdata(int add,
                        int value)
                 throws SIMException
Throws:
SIMException

data

public final int data(int add)
               throws SIMException
Throws:
SIMException

data

public final void data(int add,
                       int value)
                throws SIMException
Throws:
SIMException

popw

public final int popw()
               throws SIMException
Pop a word from the stack.

Throws:
SIMException

pop

public final int pop()
              throws SIMException
Pop a byte from the stack

Throws:
SIMException

pushw

public final void pushw(int value)
                 throws SIMException
Push a word in to the stack.

Throws:
SIMException

push

public final void push(int value)
                throws SIMException
Push a byte in to the stack.

Throws:
SIMException

reset

public void reset()
           throws SIMException
Description copied from class: AbstractCPU
Reset the CPU and call all installed ResetListener.

Reset is performed in this order :

Specified by:
reset in interface Hardware
Overrides:
reset in class AbstractCPU
Throws:
SIMException

sfrIsBit

public boolean sfrIsBit(int add,
                        int mask)
                 throws SIMException
Throws:
SIMException

sfrSetBit

public void sfrSetBit(int add,
                      int mask)
               throws SIMException
Throws:
SIMException

setDptrIndex

public final void setDptrIndex(int i)
                        throws SIMException
Set the current DPTR index

Throws:
SIMException

getDptr

public final int getDptr(int i)
                  throws SIMException
Return the DPTR register with the specified index

Throws:
SIMException

fireISR

public int fireISR(Interrupt isr)
            throws SIMException
Description copied from class: AbstractCPU
This function must be overridden from sub class that implements interrupt.

Specified by:
fireISR in interface CPU
Overrides:
fireISR in class AbstractCPU
Throws:
SIMException

setAuxrDptrEnabled

protected final void setAuxrDptrEnabled()
Enabled the standard AUXR1 dptr. Must be calld before initializations.

Since:
1.02

jmce - 1_02