de.michab.simulator.mos6502.c64
Class C64Core

java.lang.Object
  extended byde.michab.simulator.mos6502.c64.C64Core
All Implemented Interfaces:
java.util.EventListener, java.awt.event.KeyListener

public class C64Core
extends java.lang.Object
implements java.awt.event.KeyListener

A facade to a single instance of a Commodore 64. Years ago that cost $1000, today only a constructor is needed. The KeyListener implemented by this class has to be connected to the component receiving the emulation's keyboard input.

The display property provides a component that represents the Commodore 64's video screen. This has to be displayed in a GUI environment.

As soon as the minimum setup -- connect of the KeyListener and display of the display component -- has been done a call to the start() method starts the emulation.

Version:
$Revision: 1.42 $
Author:
Michael G. Binz

Field Summary
static int ADR_COLOR_RAM_NEW
          Position of the color ram.
static int D_JOYSTICK_0
           
static int D_JOYSTICK_1
           
static int D_KEYBOARD
           
static java.lang.String IMAGE_NAME
           
static int NTSC_TICKS_PER_SEC
           
static int PAL_TICKS_PER_SEC
           
 
Constructor Summary
C64Core()
          Creates an instance of a Commodore 64.
 
Method Summary
 void addPropertyChangeListener(java.lang.String name, java.beans.PropertyChangeListener pcl)
          Adds a property change listener to this bean.
 Chip[] getCia()
          Returns a reference to the emulation's pair of CIA chips.
 Processor getCpu()
          Returns a reference to the emulation's CPU.
 java.awt.Component getDisplay()
          Returns a reference on the component that the display is drawn into.
 java.awt.Color getFrameColor()
          Returns the frame color as set in the C64's VIC chip.
 SystemFile getImageFile()
          Get the currently attached image file.
 byte[][] getImageFileDirectory()
          Returns the directory of the currently loaded image file.
 int getInputDevice()
          Returns the currently selected input device.
 Memory getMemory()
          Get a reference to the emulation's memory.
 Chip getSid()
          Returns a reference to the emulation's sound interface device (aka SID).
 Chip getVic()
          Returns a reference to the emulation's video interface chip (aka VIC).
 boolean isImageFileValid(SystemFile file)
          Check if the passed file is a valid image file.
 boolean isSoundOn()
          Check whether sound is enabled.
 void keyPressed(java.awt.event.KeyEvent e)
           
 void keyReleased(java.awt.event.KeyEvent e)
           
 void keyTyped(java.awt.event.KeyEvent e)
           
 void load(byte[] fileName)
          Load and start a program.
 void removePropertyChangeListener(java.lang.String name, java.beans.PropertyChangeListener pcl)
          Remove a property change listener from this bean.
 void reset()
          Performs a soft reset.
 void reset(boolean hard)
          Reset the emulation.
 void setImageFile(SystemFile file)
          Attaches a file to the emulator.
 void setInputDevice(int which)
          Selects an input device: joystick 1, joystick 2, or keyboard.
 void setSoundOn(boolean what)
          Switch sound on or off.
 void shutdown()
          Shutdown the emulator and release all resources held.
 void start()
          Starts execution of the system.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IMAGE_NAME

public static final java.lang.String IMAGE_NAME
See Also:
Constant Field Values

D_KEYBOARD

public static final int D_KEYBOARD
See Also:
setInputDevice(int), Constant Field Values

D_JOYSTICK_0

public static final int D_JOYSTICK_0
See Also:
setInputDevice(int), Constant Field Values

D_JOYSTICK_1

public static final int D_JOYSTICK_1
See Also:
setInputDevice(int), Constant Field Values

ADR_COLOR_RAM_NEW

public static final int ADR_COLOR_RAM_NEW
Position of the color ram. This is non-moveable.

See Also:
Constant Field Values

PAL_TICKS_PER_SEC

public static final int PAL_TICKS_PER_SEC
See Also:
Constant Field Values

NTSC_TICKS_PER_SEC

public static final int NTSC_TICKS_PER_SEC
See Also:
Constant Field Values
Constructor Detail

C64Core

public C64Core()
Creates an instance of a Commodore 64. Note that the thread priority of the calling thread is used as a reference priority. This means that other threads that are created to control the contained chips are placed on priority levels relative to the one of the calling thread.

Method Detail

isImageFileValid

public boolean isImageFileValid(SystemFile file)
Check if the passed file is a valid image file.

Parameters:
file - The file to check.

setImageFile

public void setImageFile(SystemFile file)
Attaches a file to the emulator. This is the bound property IMAGE_NAME.

Parameters:
file - The file to attach.

getImageFile

public SystemFile getImageFile()
Get the currently attached image file. Bound property IMAGE_NAME.

Returns:
The currently attached image file. Returns null if no image file is attached.

getImageFileDirectory

public byte[][] getImageFileDirectory()
Returns the directory of the currently loaded image file. If none is loaded null is returned. Note that this is the directory structure *inside* the image file, not the directory that holds the image file itself. The array entries contain the valid input for the load() method.

See Also:
load(byte[])

load

public void load(byte[] fileName)
Load and start a program. Note that an image file has to be already been loaded. Calling this method is equivalent to entering

   LOAD "fileName",8,1
RUN
on the 64's command line. Note that the ",8" part is autodetected so don't worry about that.

Parameters:
fileName - The name of the file to load in CBM ASCII. This file has to be contained in the currently set image file. The name passed in here should also be part of the directory list of the image file. If the file can't be found a C64 error message is printed.
See Also:
setImageFile(SystemFile), getImageFileDirectory()

reset

public void reset(boolean hard)
Reset the emulation.

Parameters:
hard - A module is detected if the memory location 0x8004 and following hold the string 'CBM80' in Commodore ASCII. If this is the case a reset results in a JMP($8000) which was used by many games to get reset save. Passing true here results in a reset even in case a module marker exists.

reset

public void reset()
Performs a soft reset.

See Also:
reset(boolean)

shutdown

public void shutdown()
Shutdown the emulator and release all resources held. It is not possible to restart after shutdown() was called.


start

public void start()
Starts execution of the system.


getVic

public Chip getVic()
Returns a reference to the emulation's video interface chip (aka VIC).


getSid

public Chip getSid()
Returns a reference to the emulation's sound interface device (aka SID).


getCia

public Chip[] getCia()
Returns a reference to the emulation's pair of CIA chips.


getCpu

public Processor getCpu()
Returns a reference to the emulation's CPU.


getMemory

public Memory getMemory()
Get a reference to the emulation's memory.


getDisplay

public java.awt.Component getDisplay()
Returns a reference on the component that the display is drawn into.

Returns:
The hot component containing the emulation's raster screen.

getFrameColor

public java.awt.Color getFrameColor()
Returns the frame color as set in the C64's VIC chip. The returned color can be used for advanced embedding of the display component in a user interface.

Returns:
The current frame colour.

getInputDevice

public int getInputDevice()
Returns the currently selected input device.

Returns:
One of the constants D_JOYSTICK_0, D_JOYSTICK_1 or D_KEYBOARD.

setInputDevice

public void setInputDevice(int which)
Selects an input device: joystick 1, joystick 2, or keyboard.

Parameters:
which - One of the constants D_JOYSTICK_0, D_JOYSTICK_1 or D_KEYBOARD.

isSoundOn

public boolean isSoundOn()
Check whether sound is enabled.

Returns:
true if sound is enabled, false otherwise.

setSoundOn

public void setSoundOn(boolean what)
Switch sound on or off.

Parameters:
what - true to switch sound on, false otherwise.

addPropertyChangeListener

public void addPropertyChangeListener(java.lang.String name,
                                      java.beans.PropertyChangeListener pcl)
Adds a property change listener to this bean.


removePropertyChangeListener

public void removePropertyChangeListener(java.lang.String name,
                                         java.beans.PropertyChangeListener pcl)
Remove a property change listener from this bean.


keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Specified by:
keyTyped in interface java.awt.event.KeyListener

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Specified by:
keyReleased in interface java.awt.event.KeyListener