org.razvan.jzx
Class BaseSpectrum

java.lang.Object
  extended by org.razvan.jzx.BaseComponent
      extended by org.razvan.jzx.BaseSpectrum
Direct Known Subclasses:
Spectrum, Spectrum

public abstract class BaseSpectrum
extends BaseComponent

Base class extended by all Spectrum models (48k, 128k).

This class provides basic, common spectrum functionality for the various spectrum models.

Author:
Razvan Surdulescu (c) 2001 - 2006, Erik Kunze (c) 1995, 1996, 1997, Des Herriott (c) 1993, 1994
You may use and distribute this software for free provided you include this copyright notice. You may not sell this software, use my name for publicity reasons or modify the code without permission from me.

Field Summary
static long FREQUENCY_MS
          The 20ms frequency of the interrupt clock.
static int ISSUE_2
          48k Spectrum model 2 (issue 2)
static int ISSUE_3
          48k Spectrum model 3 (issue 3)
protected  Clock m_clock
          The interrupt clock.
protected  java.awt.Container m_container
          Component that decorates the screen object for display in a Frame, Applet, etc.
protected  Z80 m_cpu
          Contained reference to the Z80 CPU.
protected  int m_cyclesLine
          The number of CPU T-States per TV line.
protected  long m_frequency
           
protected  BaseIO m_io
          Contained reference to the I/O object.
protected  int m_issue
          The model (issue) of this Spectrum.
protected  BaseKeyboard m_keyboard
          Contained reference to the keyboard object.
protected  BaseMemory m_memory
          Contained reference to the memory object.
protected  int m_scale
          The current scale value for this Spectrum.
protected  BaseScreen m_screen
          Contained reference to the screen object.
protected  java.awt.Label m_status
          Label used to display various status messages.
protected  int m_tvLines
          The number of lines per TV frame.
protected  int m_vline
          The current vertical line being drawn.
 
Fields inherited from class org.razvan.jzx.BaseComponent
m_logger, m_spectrum
 
Constructor Summary
BaseSpectrum()
           
 
Method Summary
 void emulate()
          The main emulator loop.
 java.awt.Component getContainer()
          Return a Container that decorates the Spectrum screen and adds other UI elements such as a status bar.
 Z80 getCPU()
          Trivial accessor for this Spectrum's CPU.
 long getFrequency()
          Get the frequency used by the m_clock.
 BaseIO getIO()
          Trivial accessor for this Spectrum's I/O.
 int getIssue()
          Trivial accessor for the issue (model) of this Spectrum.
 BaseKeyboard getKeyboard()
          Trivial accessor for this Spectrum's keyboard.
 BaseMemory getMemory()
          Trivial accessor for this Spectrum's memory.
abstract  java.lang.String getMode()
          String that describes the type of Spectrum ("48", "128").
 int getScale()
          Trivial accessor for the scale parameter of this Spectrum.
 BaseScreen getScreen()
          Trivial accessor for this Spectrum's screen.
 int getVline()
          Trivial accessor for the current TV line being drawn.
 void init(BaseSpectrum spectrum, ILogger logger)
          Allocate the clock object, and initialize all contained references (CPU, memory, I/O, screen and keyboard.)
 void load(BaseLoader loader)
          Load the Spectrum contents from the given loader, by calling the load() method of all contained components.
 void pause()
          Pause the emulation (asynchronous).
 void reset()
          Reset all contained references (CPU, memory, I/O, screen and keyboard.)
 void setFrequency(long frequency)
          Set the frequency used by the m_clock.
 void setScale(int scale)
          Trivial mutator for the scale parameter of this Spectrum.
 void stop()
          Stop the emulation (asynchronous.)
 void terminate()
          Terminate all contained references (CPU, memory, I/O, screen and keyboard) and subsequently set them to null.
 void unpause()
          Unpause the emulation (asynchronous).
 void update()
           
 
Methods inherited from class org.razvan.jzx.BaseComponent
getSpectrum
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FREQUENCY_MS

public static final long FREQUENCY_MS
The 20ms frequency of the interrupt clock. NOTE: This is set to 19 (instead of 20) because many games are frame-synchronized, and if they miss a screen refresh even by a little they wait until the next one. This means that roughly one out of two times, they will wait a frame too long. This effectively reduces the framerate by 50% to around 30FPS. By setting the frequency to 19, we guarantee that an interrupt will have arrived by the next frame, so the effective framerate is around 50FPS.

See Also:
Constant Field Values

ISSUE_2

public static final int ISSUE_2
48k Spectrum model 2 (issue 2)

See Also:
Constant Field Values

ISSUE_3

public static final int ISSUE_3
48k Spectrum model 3 (issue 3)

See Also:
Constant Field Values

m_status

protected java.awt.Label m_status
Label used to display various status messages.


m_cpu

protected Z80 m_cpu
Contained reference to the Z80 CPU.


m_memory

protected BaseMemory m_memory
Contained reference to the memory object.


m_io

protected BaseIO m_io
Contained reference to the I/O object.


m_screen

protected BaseScreen m_screen
Contained reference to the screen object.


m_container

protected java.awt.Container m_container
Component that decorates the screen object for display in a Frame, Applet, etc.


m_keyboard

protected BaseKeyboard m_keyboard
Contained reference to the keyboard object.


m_clock

protected Clock m_clock
The interrupt clock.


m_frequency

protected long m_frequency

m_issue

protected int m_issue
The model (issue) of this Spectrum.


m_vline

protected int m_vline
The current vertical line being drawn.


m_scale

protected int m_scale
The current scale value for this Spectrum.

This value is retrieved by the screen object during its init() phase.


m_tvLines

protected int m_tvLines
The number of lines per TV frame.

This value is different for the different Spectrum models.


m_cyclesLine

protected int m_cyclesLine
The number of CPU T-States per TV line.

This value is different for the different Spectrum models.

Constructor Detail

BaseSpectrum

public BaseSpectrum()
Method Detail

init

public void init(BaseSpectrum spectrum,
                 ILogger logger)
Allocate the clock object, and initialize all contained references (CPU, memory, I/O, screen and keyboard.)

Overrides:
init in class BaseComponent

reset

public void reset()
Reset all contained references (CPU, memory, I/O, screen and keyboard.)

Specified by:
reset in class BaseComponent

terminate

public void terminate()
Terminate all contained references (CPU, memory, I/O, screen and keyboard) and subsequently set them to null.

Overrides:
terminate in class BaseComponent

getIssue

public int getIssue()
Trivial accessor for the issue (model) of this Spectrum.


getScale

public int getScale()
Trivial accessor for the scale parameter of this Spectrum.

This method is called by the screen object in its init() method.


setScale

public void setScale(int scale)
Trivial mutator for the scale parameter of this Spectrum.


getVline

public int getVline()
Trivial accessor for the current TV line being drawn.


getFrequency

public long getFrequency()
Get the frequency used by the m_clock.

Returns:
The clock frequency, in milliseconds

setFrequency

public void setFrequency(long frequency)
Set the frequency used by the m_clock.

Parameters:
frequency - The clock frequency, in milliseconds

getCPU

public Z80 getCPU()
Trivial accessor for this Spectrum's CPU.


getMemory

public BaseMemory getMemory()
Trivial accessor for this Spectrum's memory.


getIO

public BaseIO getIO()
Trivial accessor for this Spectrum's I/O.


getScreen

public BaseScreen getScreen()
Trivial accessor for this Spectrum's screen.


getContainer

public java.awt.Component getContainer()
Return a Container that decorates the Spectrum screen and adds other UI elements such as a status bar.


getKeyboard

public BaseKeyboard getKeyboard()
Trivial accessor for this Spectrum's keyboard.


getMode

public abstract java.lang.String getMode()
String that describes the type of Spectrum ("48", "128").


emulate

public void emulate()
The main emulator loop.

The steps performed are as follows:


update

public void update()

pause

public void pause()
Pause the emulation (asynchronous).


unpause

public void unpause()
Unpause the emulation (asynchronous).


stop

public void stop()
Stop the emulation (asynchronous.)


load

public void load(BaseLoader loader)
Load the Spectrum contents from the given loader, by calling the load() method of all contained components.

Specified by:
load in class BaseComponent