HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML

"ZX Spectrum Emulator in Java"
Vol. 7, Issue 7, p. 60


Listing 1

public abstract class BaseComponent
protected BaseSpectrum m_spectrum;
public BaseSpectrum getSpectrum() {
return m_spectrum;
public void init(BaseSpectrum spectrum) {
m_spectrum = spectrum;
public void terminate() {
m_spectrum = null;
public abstract void reset();
public abstract void load(BaseLoader loader);

Listing 2
while (true) {
states = current CPU state count
if (states >= STATES-PER-LINE) {
states = (states - STATES-PER-LINE)
increment line count
if (lines == TV-LINES) {
lines = 0
refresh screen
wait for the next clock interrupt
interrupt the CPU
execute next CPU instruction

Listing 3

public int read8(int addr16) {
int data = m_frame[(addr16 >> 14)][(addr16 & 0x3FFF)];
return (data & 0xff);
public int read16(int addr16) {
int high = (read8((addr16 + 1) & 0xFFFF) << 8);
int low = read8(addr16);
return (high | low);

Listing 4
private int[] m_data;
private MemoryImageSource m_memoryImageSource;
// RGB data
m_data = new int[SCREEN_WIDTH * SCREEN_HEIGHT];
m_memoryImageSource = new MemoryImageSource
public void paint(Graphics g) {
for every 'address' in Video RAM {
let 'pixels' be the byte at that address
for every 'bit' in 'pixels' {
let '(x, y)' be the Cartesian coordinates of 'bit'
let 'color' be the RGB color of 'bit'
m_data['(x, y)'] = 'color'
g.drawImage(m_offscreenImage, 0, 0, this);

Additional Source Code for this Article

  • The online source for the emulator is in jzx_source.zip.

  • The online compiled classes for the emulator are in jzx.jar.

  • To run the emulator, put jzx.jar in a folder on your hard drive, then unzip roms.zip in the same location as jzx.jar.

  • Launch the emulator as follows:
    + Sun JDK: java -jar jzx.jar [parameters]
    + Sun JDK: java -classpath jzx.jar org.razvan.jzx.JZXFrame [parameters]
    + Microsoft JDK: jview /cp:p jzx.jar org.razvan.jzx.JZXFrame [parameters]

  • The command line [parameters] you can specify are as follows:
    -scale x: Scale the window size by 'x', where 'x' can be 1, 2 or 3.
    -mode m: Start the emulator in 48k ('m' = 48) or 128k ('m' = 128) mode.
    -snapshot s: Load a given .Z80 snapshot file into the emulator.

    All Rights Reserved
    Copyright ©  2004 SYS-CON Media, Inc.
      E-mail: [email protected]

    Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.