|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.razvan.jzx.BaseComponent org.razvan.jzx.BaseMemory
public abstract class BaseMemory
Base class extended by all memory components that comprise the emulator.
This class provides basic, common memory functionality for the memory subsystem of the emulator. Specific methods are overriden or implemented so as to comply with the Spectrum 48k and the Spectrum 128k models.
Memory
,
Memory
Field Summary | |
---|---|
protected byte[][] |
m_frame
Maps the frame number to the physical page data. |
protected int[] |
m_frameToPage
Maps a frame number to a physical page number. |
protected byte[][] |
m_page
The full memory array. |
protected BaseScreen |
m_screen
Cached reference to the screen component. |
static int |
PAGE_SIZE
The size, in bytes, for a memory page. |
static int |
RAM0
The first RAM page. |
static int |
RAM1
The second RAM page. |
static int |
RAM2
The third RAM page. |
static int |
RAM3
The fourth RAM page. |
static int |
RAM4
The fifth RAM page. |
static int |
RAM5
The sixth RAM page. |
static int |
RAM6
The seventh RAM page. |
static int |
RAM7
The eighth RAM page. |
static int |
ROM0
The first ROM page. |
static int |
ROM1
The second ROM page. |
static int |
ROM2
The third ROM page. |
static int |
ROM3
The fourth ROM page. |
Fields inherited from class org.razvan.jzx.BaseComponent |
---|
m_logger, m_spectrum |
Constructor Summary | |
---|---|
BaseMemory()
|
Method Summary | |
---|---|
byte[] |
getBytes(int page)
Returns the byte array that comprises a particular page. |
void |
init(BaseSpectrum spectrum,
ILogger logger)
Allocate the memory arrays, cache the screen component and pages in the appropriate memory pages. |
void |
load(BaseLoader loader)
Load the memory contents from the given BaseLoader object. |
void |
pageIn(int frame,
int page)
Maps a particular physical page into a given virtual frame number. |
int |
read16(int addr16)
Reads a word starting at a particular 16-bit address. |
int |
read8(int addr16)
Reads a byte from a particular 16-bit address. |
protected void |
readROM(java.lang.String name,
byte[] page)
Load the contents of a ROM file into the given memory page. |
void |
terminate()
Sets the memory arrays to null and releases the cached screen reference. |
java.lang.String |
toString()
Return a string representation of the memory state, which is useful for debugging. |
void |
write16(int addr16,
int val16)
Writes a word starting at a particular 16-bit address. |
void |
write8(int addr16,
int val8)
Writes a byte to a particular 16-bit address. |
Methods inherited from class org.razvan.jzx.BaseComponent |
---|
getSpectrum, reset |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int PAGE_SIZE
public static final int ROM0
public static final int ROM1
public static final int ROM2
public static final int ROM3
public static final int RAM0
public static final int RAM1
public static final int RAM2
public static final int RAM3
public static final int RAM4
public static final int RAM5
public static final int RAM6
public static final int RAM7
protected int[] m_frameToPage
There are four possible frame numbers (0 to 3.)
protected byte[][] m_frame
There are four possible frame numbers (0 to 3.)
protected byte[][] m_page
The sixteen possible phisical pages (4 ROM pages and 12 RAM pages.)
protected BaseScreen m_screen
This is used to update the screen whenever the appropriate memory area is modified.
Constructor Detail |
---|
public BaseMemory()
Method Detail |
---|
public void init(BaseSpectrum spectrum, ILogger logger)
Note that the cached screen reference can be null after this call, in the event that the BaseSpectrum parameter is itself null. This is allowed for "headless" memory objects that are not tied to a particular BaseSpectrum instance. This is used for loading the snapshot data into a memory instance, that is then copied directly into the physical BaseSpectrum memory instance.
init
in class BaseComponent
pageIn(int, int)
public void terminate()
terminate
in class BaseComponent
protected void readROM(java.lang.String name, byte[] page) throws java.io.IOException
The ROM file is specified as a Java Resource and loaded by means of Class.getResource(String).
name
- The name of the resource where the ROM file resides.page
- The memory page into which to load the ROM file.
java.io.IOException
- Thrown if the resource is not found or an
error occurs during reading.public void pageIn(int frame, int page)
The method sets:
frame
- The virtual frame number. You cannot
map a RAM page into frame 0.page
- The physical page number.public byte[] getBytes(int page)
public int read8(int addr16)
The address is mapped into a frame number by taking the first two bits, and then frame number is then mapped into a physical page. The remaining address bits are used to index into the physical page.
addr16
- The 16-bit address to read from.
public void write8(int addr16, int val8)
The address is mapped into a frame number by taking the first two bits, and then frame number is then mapped into a physical page. The remaining address bits are used to index into the physical page.
Nothing is written to a ROM page.
If the address falls into the memory mapped area of the screen memory, the screen object is updated appropriately.
addr16
- The 16-bit address to write to.val8
- The 8 bits to write at the specified address.public int read16(int addr16)
The method calls read8() for two consecutive addresses and collates the results.
addr16
- The 16-bit address to start reading from.
read8(int)
public void write16(int addr16, int val16)
The method calls write8() for two consecutive addresses, with the two halves of the specified argument.
addr16
- The 16-bit address to start writing to.val16
- The 16 bits to start writing at the specified
address.write16(int, int)
public void load(BaseLoader loader)
The BaseLoader contains a "headless" memory object inside it, whose page contents are copied into the page contents of "this" memory object.
load
in class BaseComponent
BaseLoader
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |