public class MC68000Cpu
extends java.lang.Object
JavaComm
) which are normally illegal (A line)
instructions but are used to communicate with the TrapDispatcher.Modifier and Type | Field and Description |
---|---|
int[] |
addr_regs |
protected int |
currentInstructionAddress |
static int |
cutOff |
int[] |
data_regs |
protected java.lang.StringBuilder |
disasmBuffer |
protected ExternalInterruptHandler[] |
externalInterruptHandlersList |
protected Instruction[] |
i_table |
protected ExternalInterruptHandler |
ieh |
static int |
INTERRUPT_FLAGS_MASK |
protected int[] |
interruptLevel |
protected boolean[] |
interruptSignaled |
protected short[] |
mainMemory |
protected int |
nbrOfInterruptHandlers |
protected boolean |
newInterruptGenerated |
int |
pc_reg |
int[] |
pcs |
int |
ramSize |
protected java.util.Random |
randomNumber |
int |
reg_sr |
int |
reg_ssp |
int |
reg_usp |
Screen |
screen |
protected int |
screenStart |
protected int |
screenStop |
int |
stopNow |
static int |
SUPERVISOR_FLAG |
protected int |
totMemSize |
protected int |
totRamSize |
protected int |
totRamSizeForLong |
protected int |
totRamSizeForWord |
static int |
TRACE_FLAG |
TrapDispatcher |
trapDispatcher |
Constructor and Description |
---|
MC68000Cpu(int size,
inifile.IniFile iniFile,
int romSize,
int videoRamSize)
Creates the object.
|
MC68000Cpu(int size,
int romSize,
int videoRamSize)
Creates the "naked" object, this isn't really useful except for testing.
|
MC68000Cpu(int size,
Screen screen,
inifile.IniFile iniFile,
int romSize)
Creates the object.
|
Modifier and Type | Method and Description |
---|---|
void |
addInstruction(int opcode,
Instruction i)
Adds an instruction to the list (array) of instructions
|
void |
clearInterruptHandlers()
Clears all external interrupt handlers - after this there are no more external interrupt handlers registered with this CPU.
|
void |
combineBlocks()
This combines two blocks (source 1, source2) with alpha blending and puts the result into the destination.
|
DisassembledOperand |
disassembleDstEA(int address,
int mode,
int reg,
Size sz) |
protected DisassembledOperand |
disassembleEA(int address,
int mode,
int reg,
Size sz,
boolean is_src) |
DisassembledOperand |
disassembleSrcEA(int address,
int mode,
int reg,
Size sz) |
int |
execute()
Executes one single instruction.
|
void |
executeContinuous()
Continuous execution loop.
|
int |
findInMemory(int startAddress,
int stopAddress,
short[] toFind)
Finds consecutive shorts in memory.
|
int |
findInMemory(int startAddress,
int stopAddress,
short[] toFind,
java.lang.String addString)
Finds consecutive shorts followed by a string in memory.
|
int |
findInMemory(int startAddress,
int stopAddress,
java.lang.String toFind)
Finds a string in memory.
|
void |
generateInterrupt()
This is called by an external level 2 interrupt handler wishing to signal an external interrupt.
|
void |
generateInterrupt(int interruptIndex)
This is called by an external interrupt handler wishing to signal an external interrupt.
|
int |
getDisplacement()
Gets the displacement and increments the PC.
|
inifile.IniFile |
getInifile()
Gets the
Inifile used when creating this object. |
Instruction |
getInstructionFor(int opcode)
Gets the instruction for an opcode.
|
int |
getLinkageBlock()
Gets the address of the start of the linkage block = end of RAM.
|
short[] |
getMemory()
Get the memory used by this cpu for some sort of "dma".
|
java.lang.String |
getRomFile()
Returns the name of the last romfile loaded.
|
Screen |
getScreen()
Gets the screen used by this object.
|
int[] |
getScreenAddresses()
Gets the address of the start and end of the screen.
|
boolean |
isRomLoadedOk()
Checks whether ROM was loaded OK (or some other error occurred).
|
boolean |
isSupervisorMode() |
boolean |
loadRomImage(java.lang.String filePath,
java.net.URL fileURL)
Loads a rom image into the address space.
|
int |
memBoundsOK(int address,
int maxExten) |
void |
moveBlock()
Move a block of pixels around (for 8 and 16 bit modes only!).
|
void |
raiseException(int vector)
Raises the exception of that vector.
|
void |
raiseSRException()
Special Status register exception.
|
int |
readableSize()
Gets the highest readable (not necessarily writable) memory location.
|
int |
readFromBuffer(int address,
int nbrOfBytes,
java.nio.ByteBuffer buffer,
int startInBuffer)
Reads bytes from a buffer and writes them into memory.
|
protected int |
readFromBuffer(int address,
int nbrOfBytes,
java.nio.ByteBuffer buffer,
int startInBuffer,
boolean specialRead)
Reads bytes from a ByteBuffer and writes them into memory.
|
int |
readFromFile(int address,
int nbrOfBytes,
java.nio.channels.FileChannel inChannel)
Read bytes from a filechannel and write them into memory.
|
int |
readMemoryByte(int address)
Reads an unsigned byte from memory.
|
int |
readMemoryByteSigned(int address)
Reads a signed byte from memory.
|
int |
readMemoryLong(int address)
Reads a long word.
|
int |
readMemoryLongPC()
Reads a long word at (PC).
|
int |
readMemoryLongPCinc()
Reads a long word at (PC) and increases the PC by 2 (actually by 4).
|
short |
readMemoryShort(int address)
Reads a word as signed short.
|
int |
readMemoryWord(int address)
Reads an unsigned word from memory.
|
int |
readMemoryWordPC()
Reads an unsigned word at address (PC).
|
int |
readMemoryWordPCInc()
Reads an unsigned word at address (PC) and increases PC by 1.
|
int |
readMemoryWordPCSigned()
Reads a word at address PC and returns the word as a signed int.
|
int |
readMemoryWordPCSignedInc()
Reads an word at address PC, increases PC by 1 and returns the word as a signed int.
|
int |
readMemoryWordSigned(int address)
Reads a word and returns it as signed int.
|
java.lang.String |
readSmsqeString(int address)
Returns a java String from an SMSQE string at a certain address MAKING accented chars conversion.
|
void |
registerInterruptHandler(ExternalInterruptHandler eh)
Registers an external interrupt handler with the CPU.
|
int |
registerInterruptHandler(ExternalInterruptHandler eh,
int intLevel)
Registers an external interrupt handler with the CPU - ATTENTION:
Only ONE external interrupt of the same class will be registered!
|
void |
removeKeyrow(int row,
int col)
Unsets the keyrow parameter for this key (row and col).
|
void |
reset()
Resets this CPU.
|
void |
setCopyScreen(int QLScreenMode,
int origins)
This switches QL screen emulation on or off.
|
void |
setEmuScreenMode(int mode)
Sets the display mode when emulating a QL compatible screen, a fall through to the corresponding screen routine.
|
void |
setKeyrow(int row,
int col)
Sets the keyrow parameter for this key (row and col).
|
void |
setScreenMode(int mode)
Sets the display mode for a QL compatible screen, a fall through to the corresponding screen routine.
|
void |
setSR(int value)
Sets the status register with a certain value.
|
void |
setTrapDispatcher(TrapDispatcher td)
Sets the trap dispatcher for this CPU, which is called whenever a JAVAComm instruction (such as for some device drivers) is encountered.
|
void |
setupSMSQE(boolean clearMem)
Resets this CPU, sets up SMSQ/E and prepares the CPU for starting execution..
|
static int |
signExtendByte(int value)
Sign extend a byte.
|
static int |
signExtendWord(int value)
Sign extend a word.
|
void |
testTrace()
Sets the trace flag.
|
void |
writeMemoryByte(int address,
int value)
Writes a byte to memory.
|
void |
writeMemoryLong(int address,
int value)
Writes a long to the memory.
|
void |
writeMemoryShort(int address,
short value)
Writes a short to memory.
|
void |
writeMemoryWord(int address,
int value)
Writes a word to memory.
|
void |
writeSmsqeString(int address,
java.lang.String s,
boolean writeLength,
int maxLength)
Writes a java String as an SMSQE string to a certain address MAKING accented chars conversion.
|
void |
writeSmsqeString(int address,
java.lang.String s,
int maxLength)
Writes a java String as an SMSQE string to a certain address MAKING accented chars conversion.
|
int |
writeToBuffer(java.nio.ByteBuffer buffer,
int offsetInBuffer)
Writes bytes read from the memory to a ByteBuffer.
|
int |
writeToBuffer(java.nio.ByteBuffer buffer,
int A1,
int bytesToWrite)
Writes bytes read from the memory to a ByteBuffer.
|
java.nio.ByteBuffer |
writeToBuffer(int offsetInBuffer)
Creates a ByteBuffer and writes bytes read from the memory to it.
|
int |
writeToFile(int address,
int nbrOfBytes,
java.nio.channels.FileChannel outChannel)
Write bytes read from memory to a filechannel.
|
protected ExternalInterruptHandler[] externalInterruptHandlersList
protected boolean[] interruptSignaled
protected int[] interruptLevel
protected int nbrOfInterruptHandlers
protected boolean newInterruptGenerated
public TrapDispatcher trapDispatcher
protected final short[] mainMemory
public static final int cutOff
protected int screenStart
protected int screenStop
public Screen screen
public int ramSize
protected int totRamSize
protected int totRamSizeForLong
protected int totRamSizeForWord
protected int totMemSize
protected java.util.Random randomNumber
public final int[] data_regs
public final int[] addr_regs
public int pc_reg
public int reg_sr
public int reg_usp
public int reg_ssp
protected int currentInstructionAddress
protected java.lang.StringBuilder disasmBuffer
protected final Instruction[] i_table
protected ExternalInterruptHandler ieh
public static final int INTERRUPT_FLAGS_MASK
public static final int SUPERVISOR_FLAG
public static final int TRACE_FLAG
public int stopNow
public int[] pcs
public MC68000Cpu(int size, int romSize, int videoRamSize)
size
- the size of ram in bytes. This is allocated when the object is created.romSize
- the size of the ROM image. Loaded after the RAM image.videoRamSize
- size,in bytes, of screen memory to be allocated here.public MC68000Cpu(int size, inifile.IniFile iniFile, int romSize, int videoRamSize)
size
- the size of ram in bytes.iniFile
- my .ini file with options to set.romSize
- the size of the ROM image. Loaded after the RAM image.videoRamSize
- size,in bytes, of screen memory to be allocated here.public MC68000Cpu(int size, Screen screen, inifile.IniFile iniFile, int romSize)
size
- the size of ram in bytes. This is NOT allocated when the object is created, but only when the OS is loaded.screen
- the screen attached to the machine.iniFile
- my .ini file with options to set.romSize
- the size of the ROM image. Loaded above RAM and VRAM.public final int execute()
public final void executeContinuous()
public void generateInterrupt()
public void registerInterruptHandler(ExternalInterruptHandler eh)
eh
- the ExternalInterruptHandler to registerpublic int registerInterruptHandler(ExternalInterruptHandler eh, int intLevel) throws java.lang.IllegalArgumentException, java.util.InputMismatchException, java.util.TooManyListenersException
eh
- the ExternalInterruptHandler to registerintLevel
- - the interrupt level that this interrupt handler generates.java.lang.IllegalArgumentException
- if interruptLevel <0 or >7java.util.InputMismatchException
- if an interrupt handler of this class is already registered with the CPU.java.util.TooManyListenersException
- if one tried to register more than 10 exception handlers.public void generateInterrupt(int interruptIndex)
interruptIndex
- the index into the interrupt handlers array for this interruptHandler.
This is the index returned by the registerInterruptHandler
method.public void clearInterruptHandlers()
public final int readMemoryByte(int address)
address
- where to read from.public final int readMemoryByteSigned(int address)
address
- where to read from.public final int readMemoryWord(int address)
address
- where to read from.public final int readMemoryWordSigned(int address)
address
- where to read from.public final int readMemoryWordPC()
public final int readMemoryWordPCInc()
public final int readMemoryWordPCSigned()
public final int readMemoryWordPCSignedInc()
public final short readMemoryShort(int address)
address
- where to read from.public final int readMemoryLong(int address)
address
- where to read from.public final int readMemoryLongPC()
public final int readMemoryLongPCinc()
public void writeMemoryByte(int address, int value)
address
- where to write to.value
- the byte to write (in the LSB of the int).public void writeMemoryWord(int address, int value)
address
- where to write to.value
- the word to write (in the LSW of the int).public void writeMemoryShort(int address, short value)
address
- where to write to.value
- the short to write.public void writeMemoryLong(int address, int value)
address
- the address where to write to.value
- the value to write.public int memBoundsOK(int address, int maxExten)
public void reset()
public void raiseException(int vector)
vector
- the exception vector to raise.public void raiseSRException()
public void setSR(int value)
value
- the value to set.public void testTrace()
public static final int signExtendByte(int value)
value
- the int containing the byte to be sign extended.public static final int signExtendWord(int value)
value
- the int containing the word to be sign extended.public boolean isSupervisorMode()
public final int getDisplacement()
public void addInstruction(int opcode, Instruction i)
opcode
- the opcode of the instruction to be added to the cpu's list of instructions. This is the index into the instructions array.i
- the instruction to add.public DisassembledOperand disassembleSrcEA(int address, int mode, int reg, Size sz)
public DisassembledOperand disassembleDstEA(int address, int mode, int reg, Size sz)
protected DisassembledOperand disassembleEA(int address, int mode, int reg, Size sz, boolean is_src)
public Instruction getInstructionFor(int opcode)
opcode
- the opcode for which to get the instruction.public int[] getScreenAddresses()
public void moveBlock()
public void combineBlocks()
public void setCopyScreen(int QLScreenMode, int origins)
origins
- origins in y screen which should correspond to (0,0) in QL screen.QLScreenMode
- the screen mode the QL screen is supposed to be in.public java.lang.String readSmsqeString(int address)
address
- where the string lies in memory.null
.
This makes character conversion from SMSQQE charset to Java charset.
public void writeSmsqeString(int address, java.lang.String s, int maxLength)
address
- - where to start writing.s
- the String
to write.maxLength
- the max length of the string to write NOT INCLUDING THE LENGTH WORD, -1 if no max length.public void writeSmsqeString(int address, java.lang.String s, boolean writeLength, int maxLength)
address
- - where to start writing.s
- the String
to write.writeLength
- true
if the length of the string should be prepended to the string (as would be usual in SMSQE)maxLength
- the max length of the string to write NOT INCLUDING THE LENGTH WORD, -1 if no max length.public int writeToFile(int address, int nbrOfBytes, java.nio.channels.FileChannel outChannel) throws java.io.IOException
address
- where to start reading.nbrOfBytes
- how many bytes to write.outChannel
- the channel to write to.java.io.IOException
- from the file channed I/O operations.public java.nio.ByteBuffer writeToBuffer(int offsetInBuffer)
offsetInBuffer
- nbr of bytes to add to the size, and also start of where to put these bytes in the newly created buffer.public int writeToBuffer(java.nio.ByteBuffer buffer, int offsetInBuffer)
NOTE THIS PRESUMES THAT THE START ADDRESS IS EVEN!
buffer
- the ByteBuffer into which the bytes read from memory are to be written.offsetInBuffer
- nbr of bytes to add to the size, and also start of where to put these bytes in the newly created buffer.public int writeToBuffer(java.nio.ByteBuffer buffer, int A1, int bytesToWrite)
buffer
- the ByteBuffer into which the bytes read from memory are to be written at the current position of this buffer.
THE LIMIT oF THIS BUFFER WILL BE SET TO ITS CAPACITY.A1
- where to start reading the bytes from.bytesToWrite
- nbr of bytes to write to the buffer.public int readFromFile(int address, int nbrOfBytes, java.nio.channels.FileChannel inChannel) throws java.io.IOException
address
- where to read to.nbrOfBytes
- how many bytes to read.inChannel
- the channel to read from.java.io.IOException
- from the file channed I/O operations.protected int readFromBuffer(int address, int nbrOfBytes, java.nio.ByteBuffer buffer, int startInBuffer, boolean specialRead)
address
- where to read to.nbrOfBytes
- how many bytes are to be read.buffer
- the buffer to read from.startInBuffer
- where in the buffer to start reading from.specialRead
- =true
ONLY when loading the OS, must be false
at all other times!public int readFromBuffer(int address, int nbrOfBytes, java.nio.ByteBuffer buffer, int startInBuffer)
address
- where to read to.nbrOfBytes
- how many bytes to read.buffer
- the buffer to read from.startInBuffer
- the first byte in the buffer to read from.public int findInMemory(int startAddress, int stopAddress, java.lang.String toFind)
startAddress
- where to start searching.stopAddress
- where to stop searching.toFind
- the string to find, must have an even number of characters.public int findInMemory(int startAddress, int stopAddress, short[] toFind, java.lang.String addString)
startAddress
- where to start searching.stopAddress
- where to stop searching.toFind
- the array with the consecutive shorts to find, in the order they are in that array.addString
- th additional string to find, the length of it MUST BE EVENpublic int findInMemory(int startAddress, int stopAddress, short[] toFind)
startAddress
- where to start searching.stopAddress
- where to stop searching.toFind
- the array with the consecutive shorts to find, in the order they are in that array.public void setTrapDispatcher(TrapDispatcher td)
td
- the trap dispatcherpublic void setKeyrow(int row, int col)
row
- what row (0 to 7)col
- what col (0 to 7)public void removeKeyrow(int row, int col)
row
- what row (0 to 7)col
- what col (0 to 7)public inifile.IniFile getInifile()
Inifile
used when creating this object.Inifile
used when creating this object.public void setScreenMode(int mode)
mode
- (0 or 8)public void setEmuScreenMode(int mode)
mode
- (0 or 8)public int readableSize()
public int getLinkageBlock()
public boolean isRomLoadedOk()
true
if loaded OK (CPU may proceed executing).public void setupSMSQE(boolean clearMem)
clearMem
- = true if memory should be cleared.public boolean loadRomImage(java.lang.String filePath, java.net.URL fileURL)
filePath
- name of file to load. This is present when the next parameter is null.fileURL
- url of the file to load. this must be present when the previous parameter is null.true
if ROM image loaded OK, else false
.public Screen getScreen()
public java.lang.String getRomFile()
null
if none.public short[] getMemory()
short
) used by the cpu.