|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectuk.co.javagear.Memory
public final class Memory
Emulates SMS/GG Memory and Paging Hardware. Also Handles Reading ROMs and configuring the memory appropriately.
Field Summary | |
---|---|
private int |
cartRamPage
Stores which page of cartridge RAM to use. |
private byte[][] |
cartRamPages
Array of cartridge RAM pages. |
private byte[][] |
frames
Array of memory frames. |
private boolean |
frameTwoRom
Stores whether frame 2 contains cartridge ROM or cartridge RAM. |
private int |
numberOfPages
Stores number of pages. |
private byte[][] |
pages
Array of memory pages. |
private Setup |
setup
Pointer to general parameters. |
Constructor Summary | |
---|---|
Memory(Setup set)
Memory constructor. |
Method Summary | |
---|---|
private static java.lang.String |
getExtension(java.lang.String filename)
Strip an extension from a file. |
private static java.util.zip.ZipEntry |
getRomEntry(java.util.zip.ZipInputStream zis)
Returns the first entry in the ZipInputStream that contains an SMS or GG ROM or
null if none is found. |
private void |
page(int address,
int value)
Write to a paging register. |
int |
read(int address)
Read from a memory location. |
private void |
readCart(java.io.InputStream is,
int size)
Read a cartridge's data from an InputStream . |
void |
readCart(java.net.URL url)
Read a cartridge into memory from the specified URL. |
int |
readSigned(int address)
Read a signed value from a memory location. |
int |
readWord(int address)
Read a word (two bytes) from a memory location. |
void |
reset()
Reset memory to default values. |
private int |
unsigned(int b)
Unsign an integer. |
void |
write(int address,
int value)
Write to a memory location. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private byte[][] frames
private byte[][] pages
private byte[][] cartRamPages
private boolean frameTwoRom
private int cartRamPage
private int numberOfPages
private Setup setup
Constructor Detail |
---|
public Memory(Setup set)
set
- pointer to general parameters.Method Detail |
---|
public void reset()
public void write(int address, int value)
address
- memory addressvalue
- value to writepublic int read(int address)
address
- memory location.
public int readSigned(int address)
address
- Memory address
public int readWord(int address)
address
- memory address.
private int unsigned(int b)
b
- value to unsign.
private void page(int address, int value)
address
- memory location.value
- value to write.public void readCart(java.net.URL url) throws java.io.IOException, java.lang.IllegalArgumentException
url
- URL of cartridge image.
java.io.IOException
- if an error occurs while reading the file.
java.lang.IllegalArgumentException
- if the file is neither a ROM, nor a Zip file containing one.private static java.util.zip.ZipEntry getRomEntry(java.util.zip.ZipInputStream zis) throws java.io.IOException
ZipInputStream
that contains an SMS or GG ROM or
null
if none is found. If the stream does not include a ROM or an
IOException
occurs while looking for a valid entry, the stream will be closed.
Otherwise it is left open, pointing at the ROM's contents.
zis
- an instance of ZipInputStream
, may be null
.
ZipEntry
or null
if none
were found.
java.io.IOException
- if an error occurs while reading from the stream.private void readCart(java.io.InputStream is, int size) throws java.io.IOException, java.lang.IllegalArgumentException
InputStream
. The method does not
close when it finishes reading.
is
- the stream to read the ROM's data from.size
- the size of the stream's content.
java.lang.IllegalArgumentException
- if is
is null
or
size
.
java.io.IOException
- if an error occurs while reading the file.private static java.lang.String getExtension(java.lang.String filename)
filename
- filename to strip.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |