pvbemu/src/desktop/vue/NativeVue.java

171 lines
5.8 KiB
Java

package vue;
// Native-backed emulation core implementation
class NativeVue extends Vue {
// Instance fields
private long handle; // Context address in native memory
///////////////////////////////////////////////////////////////////////////
// Constructors //
///////////////////////////////////////////////////////////////////////////
// Default constructor
private native long construct();
NativeVue() {
handle = construct();
}
///////////////////////////////////////////////////////////////////////////
// Public Methods //
///////////////////////////////////////////////////////////////////////////
// Produce a new breakpoint and add it to the collection
private native void breakpoint(long handle);
public Breakpoint breakpoint() {
var brk = super.breakpoint();
breakpoint(handle);
return brk;
}
// Release any used resources
private native void dispose(long handle);
public void dispose()
{ dispose(handle); }
// Process the simulation
private native int emulate(long handle, int maxCycles);
public int emulate(int maxCycles)
{ return emulate(handle, maxCycles); }
// Retrieve the most recent application break code
private native int getBreakCode(long handle);
public int getBreakCode() { return getBreakCode(handle); }
// Retrieve the most recent exception code
private native int getExceptionCode(long handle);
public int getExceptionCode() {
return getExceptionCode(handle);
}
// Retrieve a register value
private native int getRegister(long handle, int index, boolean system);
public int getRegister(int index, boolean system)
{ return getRegister(handle, index, system); }
// Retrieve a copy of the ROM data
private native byte[] getROM(long handle);
public byte[] getROM() { return getROM(handle); }
// Determine whether the context is native-backed
public boolean isNative() {
return true;
}
// Read a value from the CPU bus
private native int read(long handle, int address, int type);
public int read(int address, int type)
{ return read(handle, address, type); }
// Read bytes from the CPU bus
private native boolean readBytes(long handle, int address, byte[] dest,
int offset, int length);
public boolean readBytes(int address, byte[] dest, int offset, int length)
{ return readBytes(handle, address, dest, offset, length); }
// Remove a breakpoint from the collection
private native void remove(long handle, int index);
public boolean remove(Breakpoint brk) {
int index = breakpoints.indexOf(brk);
if (!super.remove(brk))
return false;
remove(handle, index);
return true;
}
// Initialize all system components
private native void reset(long handle);
public void reset()
{ reset(handle); }
// Specify a register value
private native int setRegister(long handle, int index, boolean system,
int value);
public int setRegister(int index, boolean system, int value)
{ return setRegister(handle, index, system, value); }
// Provide new ROM data
private native boolean setROM(long handle, byte[] data, int offset,
int length);
public boolean setROM(byte[] data, int offset, int length)
{ return setROM(handle, data, offset, length); }
// Write a value to the CPU bus
private native void write(long handle, int address, int type, int value);
public void write(int address, int type, int value)
{ write(handle, address, type, value); }
// Write bytes to the CPU bus
private native boolean writeBytes(long handle, int address, byte[] src,
int offset, int length);
public boolean writeBytes(int address, byte[] src, int offset, int length)
{ return writeBytes(handle, address, src, offset, length); }
///////////////////////////////////////////////////////////////////////////
// Package Methods //
///////////////////////////////////////////////////////////////////////////
// Retrieve the current state's breakpoint scenario
private native int getBreakType(long handle);
int getBreakType() {
return getBreakType(handle);
}
// Retrieve the current instruction fetch index
private native int getFetch(long handle);
int getFetch() {
return getFetch(handle);
}
// A breakpoint's address ranges have changed
private native void updateRanges(long handle, int index, int[] ranges);
void updateRanges(Breakpoint brk) {
super.updateRanges(brk);
int index = breakpoints.indexOf(brk);
if (index >= 0)
updateRanges(handle, index, brk.flattenRanges());
}
// A breakpoint's enabled/hook state has changed
private native void updateState(long handle, int index, boolean enabled,
boolean fetch, int hooks);
void updateState(Breakpoint brk) {
super.updateState(brk);
int index = breakpoints.indexOf(brk);
updateState(handle, index,
brk.isEnabled(), brk.getFetch(), brk.getHooks());
}
// A breakpoint's condition tokens have changed
private native void updateTokens(long handle, int index, int[] tokens,
int depth, int maxDepth);
void updateTokens(Breakpoint brk) {
super.updateTokens(brk);
int index = breakpoints.indexOf(brk);
if (index < 0)
return;
int maxDepth = 0;
for (var bre : breakpoints)
maxDepth = Math.max(maxDepth, bre.getDepth());
updateTokens(handle, index, brk.flattenTokens(),
brk.getDepth(), maxDepth);
}
}