org.razvan.jzx
Class BaseIO

java.lang.Object
  extended by org.razvan.jzx.BaseComponent
      extended by org.razvan.jzx.BaseIO
Direct Known Subclasses:
IO, IO

public class BaseIO
extends BaseComponent

Base class extended by all I/O components that comprise the emulator.

This class provides basic, common I/O functionality for the I/O subsystem of the emulator. Specific methods are overriden or implemented so as to comply with the Spectrum 48k and the Spectrum 128k 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.
See Also:
IO, IO

Field Summary
static int B_BORDER
          Bit mask used to determine the border color value.
static int B_DOWN
          Bit mask for "joystick down" event.
static int B_EAR
          Bit mask used to determien the "tape in" bit.
static int B_FIRE
          Bit mask for "joystick fire" event.
static int B_KEMPSTON
          Bit mask used to determine if the Kempston joystick is selected.
static int B_KEYBOARD
          Bit mask used to determine the keyboard value.
static int B_LEFT
          Bit mask for "joystick left" event.
static int B_MIC
          Bit mask used to determine the "tape out" bit.
static int B_RIGHT
          Bit mask for "joystick right" event.
static int B_SPEAKER
          Bit mask used to determine the speaker value.
static int B_ULA
          Bit mask used to detemine if the specified port will cause a "select" on the ULA.
static int B_UP
          Bit mask for "joystick up" event.
static int LINE_BUF_SIZE
          The size of the buffer used for generating sounds.
protected  byte[] m_buffer
          The sound buffer as it is currently being filled and played.
protected  Z80 m_cpu
          Cached reference to the Z80 component.
protected  int m_index
          The current index into the sound buffer.
protected  int[] m_inPorts
          The input port array.
protected  int[] m_keyPorts
          The keyboard port array.
protected  int m_lastBorderColor
          Last border color.
protected  BaseMemory m_memory
          Cached reference to the memory component.
protected  int[] m_outPorts
          The output port array.
protected  BaseScreen m_screen
          Cached reference to the screen component.
protected  int m_speakerLevel
           
static int P_KEMPSTON
          Kempston joystick address.
static int P_SINCLAIR1
          Port address for the Sinclair1 joystick (Interface II).
static int P_SINCLAIR2
          Port address for the Sinclair2 joystick (Interface II).
static int P_ULA
          Port address for the ULA.
static float SAMPLE_FREQ
          The sampling frequency for playing sounds with the speaker or AY chip.
 
Fields inherited from class org.razvan.jzx.BaseComponent
m_logger, m_spectrum
 
Constructor Summary
BaseIO()
           
 
Method Summary
 void advance(int tStates)
           
 void andIn(int port16, int mask8)
          INport(port16) = INport(port16) AND mask8
 void andKey(int port16, int mask8)
          KEYport(port16) = KEYport(port16) AND mask8
 void andOut(int port16, int mask8)
          OUTport(port16) = OUTport(port16) AND mask8
static int getAudioSamplesForTStates(int tStates)
           
 int in8(int port16)
          Process an I/O "in" request.
 void init(BaseSpectrum spectrum, ILogger logger)
          Allocate the port arrays and cache the Z80, memory and screen components.
 void load(BaseLoader loader)
          Extracts the saved border color and outputs it to the appropriate I/O port.
protected  int mixSound(int tStates, int val8)
           
 void orIn(int port16, int mask8)
          INport(port16) = INport(port16) OR mask8
 void orKey(int port16, int mask8)
          KEYport(port16) = KEYport(port16) OR mask8
 void orOut(int port16, int mask8)
          OUTport(port16) = OUTport(port16) OR mask8
 void out(int port16, int val8)
          Process an I/O "out" request.
 void reset()
          Set the port arrays to zero.
 void terminate()
          Release references to all cached components and port arrays.
 
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

SAMPLE_FREQ

public static final float SAMPLE_FREQ
The sampling frequency for playing sounds with the speaker or AY chip.

See Also:
Constant Field Values

LINE_BUF_SIZE

public static final int LINE_BUF_SIZE
The size of the buffer used for generating sounds.

See Also:
Constant Field Values

m_buffer

protected byte[] m_buffer
The sound buffer as it is currently being filled and played.


m_index

protected int m_index
The current index into the sound buffer.


P_ULA

public static final int P_ULA
Port address for the ULA.

See Also:
Constant Field Values

B_ULA

public static final int B_ULA
Bit mask used to detemine if the specified port will cause a "select" on the ULA.

See Also:
Constant Field Values

B_BORDER

public static final int B_BORDER
Bit mask used to determine the border color value.

See Also:
Constant Field Values

B_MIC

public static final int B_MIC
Bit mask used to determine the "tape out" bit.

See Also:
Constant Field Values

B_SPEAKER

public static final int B_SPEAKER
Bit mask used to determine the speaker value.

See Also:
Constant Field Values

B_KEYBOARD

public static final int B_KEYBOARD
Bit mask used to determine the keyboard value.

See Also:
Constant Field Values

B_EAR

public static final int B_EAR
Bit mask used to determien the "tape in" bit.

See Also:
Constant Field Values

P_KEMPSTON

public static final int P_KEMPSTON
Kempston joystick address.

See Also:
Constant Field Values

B_KEMPSTON

public static final int B_KEMPSTON
Bit mask used to determine if the Kempston joystick is selected.

See Also:
Constant Field Values

B_RIGHT

public static final int B_RIGHT
Bit mask for "joystick right" event.

See Also:
Constant Field Values

B_LEFT

public static final int B_LEFT
Bit mask for "joystick left" event.

See Also:
Constant Field Values

B_DOWN

public static final int B_DOWN
Bit mask for "joystick down" event.

See Also:
Constant Field Values

B_UP

public static final int B_UP
Bit mask for "joystick up" event.

See Also:
Constant Field Values

B_FIRE

public static final int B_FIRE
Bit mask for "joystick fire" event.

See Also:
Constant Field Values

P_SINCLAIR1

public static final int P_SINCLAIR1
Port address for the Sinclair1 joystick (Interface II).

See Also:
Constant Field Values

P_SINCLAIR2

public static final int P_SINCLAIR2
Port address for the Sinclair2 joystick (Interface II).

See Also:
Constant Field Values

m_lastBorderColor

protected int m_lastBorderColor
Last border color.

This is used to determine if the newly specified border color should trigger a screen update.


m_inPorts

protected int[] m_inPorts
The input port array.

This array is modified by the Z80 I/O instructions.


m_outPorts

protected int[] m_outPorts
The output port array.

This array is modified by the Z80 I/O instructions.


m_keyPorts

protected int[] m_keyPorts
The keyboard port array.

This array is modified by the Keyboard component directly.


m_cpu

protected Z80 m_cpu
Cached reference to the Z80 component.

This is used to increment the CPU T-states after I/O instructions.


m_memory

protected BaseMemory m_memory
Cached reference to the memory component.

This is used for all memory page modifications that are triggered by I/O instructions.


m_screen

protected BaseScreen m_screen
Cached reference to the screen component.

This is used to alter the border color.


m_speakerLevel

protected int m_speakerLevel
Constructor Detail

BaseIO

public BaseIO()
Method Detail

getAudioSamplesForTStates

public static int getAudioSamplesForTStates(int tStates)

init

public void init(BaseSpectrum spectrum,
                 ILogger logger)
Allocate the port arrays and cache the Z80, memory and screen components.

Overrides:
init in class BaseComponent

reset

public void reset()
Set the port arrays to zero.

Specified by:
reset in class BaseComponent

terminate

public void terminate()
Release references to all cached components and port arrays.

Overrides:
terminate in class BaseComponent

in8

public int in8(int port16)
Process an I/O "in" request.

The flow of this call is as follows:

See the explicit code comments for specific details.

Parameters:
port16 - The 16-bit I/O input port.
Returns:
The 8-bit value read from the I/O port.

out

public void out(int port16,
                int val8)
Process an I/O "out" request.

The flow of this call is as follows:

See the explicit code comments for specific details.

Parameters:
port16 - The 16-bit I/O output port.
val8 - The 8-bit value to write to the I/O port.

advance

public void advance(int tStates)

mixSound

protected int mixSound(int tStates,
                       int val8)

orIn

public void orIn(int port16,
                 int mask8)
INport(port16) = INport(port16) OR mask8


andIn

public void andIn(int port16,
                  int mask8)
INport(port16) = INport(port16) AND mask8


orOut

public void orOut(int port16,
                  int mask8)
OUTport(port16) = OUTport(port16) OR mask8


andOut

public void andOut(int port16,
                   int mask8)
OUTport(port16) = OUTport(port16) AND mask8


orKey

public void orKey(int port16,
                  int mask8)
KEYport(port16) = KEYport(port16) OR mask8


andKey

public void andKey(int port16,
                   int mask8)
KEYport(port16) = KEYport(port16) AND mask8


load

public void load(BaseLoader loader)
Extracts the saved border color and outputs it to the appropriate I/O port.

Specified by:
load in class BaseComponent