Adjusting naming of all-caps structs, implementing native handle as a long

This commit is contained in:
Guy Perfect 2020-10-03 14:20:56 -05:00
parent 1386d36b0d
commit 81840f71d2
21 changed files with 554 additions and 540 deletions

View File

@ -73,7 +73,7 @@ static const int8_t CYCLES[] = {
*****************************************************************************/
/* Integer addition */
static int32_t cpuAdd(VUE *vue, int left, int right) {
static int32_t cpuAdd(Vue *vue, int left, int right) {
int32_t result = left + right;
vue->cpu.psw_cy = (uint32_t) result < (uint32_t) left ? 1 : 0;
vue->cpu.psw_s = result >> 31 & 1;
@ -83,7 +83,7 @@ static int32_t cpuAdd(VUE *vue, int left, int right) {
}
/* Bitwise operation */
static void cpuBitwise(VUE *vue, int32_t result) {
static void cpuBitwise(Vue *vue, int32_t result) {
vue->cpu.program[vue->cpu.inst.reg2] = result;
vue->cpu.psw_ov = 0;
vue->cpu.psw_s = result >> 31 & 1;
@ -94,7 +94,7 @@ static void cpuBitwise(VUE *vue, int32_t result) {
#define cpuFloat(x) ((double) *(float *)&(x))
/* Determine whether the floating-point operands are reserved values */
static vbool cpuFloatReserved(VUE *vue, vbool left) {
static vbool cpuFloatReserved(Vue *vue, vbool left) {
int32_t exponent; /* Operand exponent */
int32_t operand; /* Current operand */
int x; /* Iterator */
@ -126,7 +126,7 @@ static vbool cpuFloatReserved(VUE *vue, vbool left) {
}
/* Convert a floating short to word */
static void cpuFloatConvert(VUE *vue, vbool round) {
static void cpuFloatConvert(Vue *vue, vbool round) {
int32_t bits; /* Number of bits to shift */
int32_t digits; /* Significant digits */
int32_t result; /* Output value */
@ -187,7 +187,7 @@ static void cpuFloatConvert(VUE *vue, vbool round) {
}
/* Floating-point result */
static void cpuFloatResult(VUE *vue, vbool compare, double full) {
static void cpuFloatResult(Vue *vue, vbool compare, double full) {
int32_t bits = 0x7F7FFFFF; /* Binary representation of result */
float result = *(float *)&bits; /* Operation output */
@ -223,7 +223,7 @@ static void cpuFloatResult(VUE *vue, vbool compare, double full) {
}
/* Read a system register */
static int32_t cpuGetSystemRegister(VUE *vue, int32_t index) {
static int32_t cpuGetSystemRegister(Vue *vue, int32_t index) {
switch (index) {
case VUE_ADTRE: return vue->cpu.adtre;
case VUE_EIPC : return vue->cpu.eipc;
@ -264,7 +264,7 @@ static int32_t cpuGetSystemRegister(VUE *vue, int32_t index) {
vue->cpu.program[vue->cpu.inst.reg2] = vue->cpu.access.value
/* Transfer program to another address */
static void cpuJump(VUE *vue, int32_t address) {
static void cpuJump(Vue *vue, int32_t address) {
int level = vue->cpu.psw_np ? 2 : vue->cpu.psw_ep;
vue->cpu.jumpFrom[level] = vue->cpu.pc;
vue->cpu.jumpTo [level] = address;
@ -277,7 +277,7 @@ static void cpuJump(VUE *vue, int32_t address) {
vue->cpu.inst.disp, type, vue->cpu.program[vue->cpu.inst.reg2])
/* Perform a bus read */
static vbool cpuRead(VUE *vue, int32_t address, int8_t type, int8_t fetch) {
static vbool cpuRead(Vue *vue, int32_t address, int8_t type, int8_t fetch) {
/* Perform the operation */
vue->cpu.access.address = address;
@ -295,7 +295,7 @@ static vbool cpuRead(VUE *vue, int32_t address, int8_t type, int8_t fetch) {
}
/* Write a system register */
static int32_t cpuSetSystemRegister(VUE *vue, int32_t index, int32_t value,
static int32_t cpuSetSystemRegister(Vue *vue, int32_t index, int32_t value,
vbool debug) {
switch (index) {
case VUE_ADTRE: return vue->cpu.adtre = value & 0xFFFFFFFE;
@ -362,7 +362,7 @@ static int32_t cpuSetSystemRegister(VUE *vue, int32_t index, int32_t value,
}
/* Arithmetic shift right */
static void cpuShiftArithmetic(VUE *vue, int32_t value, int32_t bits) {
static void cpuShiftArithmetic(Vue *vue, int32_t value, int32_t bits) {
bits &= 31;
/* Nothing to do */
@ -382,7 +382,7 @@ static void cpuShiftArithmetic(VUE *vue, int32_t value, int32_t bits) {
}
/* Logical shift left */
static void cpuShiftLeft(VUE *vue, int32_t value, int32_t bits) {
static void cpuShiftLeft(Vue *vue, int32_t value, int32_t bits) {
bits &= 31;
/* Nothing to do */
@ -400,7 +400,7 @@ static void cpuShiftLeft(VUE *vue, int32_t value, int32_t bits) {
}
/* Logical shift right */
static void cpuShiftRight(VUE *vue, int32_t value, int32_t bits) {
static void cpuShiftRight(Vue *vue, int32_t value, int32_t bits) {
bits &= 31;
/* Nothing to do */
@ -418,7 +418,7 @@ static void cpuShiftRight(VUE *vue, int32_t value, int32_t bits) {
}
/* Integer subtraction */
static int32_t cpuSubtract(VUE *vue, int left, int right) {
static int32_t cpuSubtract(Vue *vue, int left, int right) {
int32_t result = left - right;
vue->cpu.psw_cy = (uint32_t) result > (uint32_t) left ? 1 : 0;
vue->cpu.psw_s = result >> 31 & 1;
@ -428,7 +428,7 @@ static int32_t cpuSubtract(VUE *vue, int left, int right) {
}
/* Test a condition */
static int8_t cpuTestCondition(VUE *vue, int32_t condition) {
static int8_t cpuTestCondition(Vue *vue, int32_t condition) {
switch (condition) {
case 0: return vue->cpu.psw_ov;
case 1: return vue->cpu.psw_cy;
@ -443,7 +443,7 @@ static int8_t cpuTestCondition(VUE *vue, int32_t condition) {
}
/* Perform a bus write */
static vbool cpuWrite(VUE *vue, int32_t address, int8_t type, int32_t value) {
static vbool cpuWrite(Vue *vue, int32_t address, int8_t type, int32_t value) {
/* Prepare the operation */
vue->cpu.access.address = address;
@ -503,7 +503,7 @@ static vbool cpuWrite(VUE *vue, int32_t address, int8_t type, int32_t value) {
vue->cpu.inst.imm)
/* Branch on Condition */
static void cpuBCOND(VUE *vue) {
static void cpuBCOND(Vue *vue) {
if (!cpuTestCondition(vue, vue->cpu.inst.cond & 15))
return;
vue->cpu.cycles = 2;
@ -511,7 +511,7 @@ static void cpuBCOND(VUE *vue) {
}
/* Compare and Exchange Interlocked */
static void cpuCAXI(VUE *vue) {
static void cpuCAXI(Vue *vue) {
int32_t address =
vue->cpu.program[vue->cpu.inst.reg1] + vue->cpu.inst.disp;
int32_t left = vue->cpu.program[vue->cpu.inst.reg2];
@ -559,7 +559,7 @@ static void cpuCAXI(VUE *vue) {
cpuFloatConvert(vue, VUE_TRUE)
/* Convert Word Integer to Short */
static void cpuCVT_WS(VUE *vue) {
static void cpuCVT_WS(Vue *vue) {
int32_t bits = vue->cpu.program[vue->cpu.inst.reg1];
float result = (float) bits;
vue->cpu.program[vue->cpu.inst.reg2] = *(int32_t *)&result;
@ -571,7 +571,7 @@ static void cpuCVT_WS(VUE *vue) {
}
/* Divide */
static void cpuDIV(VUE *vue) {
static void cpuDIV(Vue *vue) {
int32_t left = vue->cpu.program[vue->cpu.inst.reg2];
int32_t right = vue->cpu.program[vue->cpu.inst.reg1];
int32_t result;
@ -602,7 +602,7 @@ static void cpuDIV(VUE *vue) {
}
/* Divide Floating Short */
static void cpuDIVF_S(VUE *vue) {
static void cpuDIVF_S(Vue *vue) {
int32_t left = vue->cpu.program[vue->cpu.inst.reg2];
int32_t right = vue->cpu.program[vue->cpu.inst.reg1];
@ -621,7 +621,7 @@ static void cpuDIVF_S(VUE *vue) {
}
/* Divide Unsigned */
static void cpuDIVU(VUE *vue) {
static void cpuDIVU(Vue *vue) {
uint32_t left = vue->cpu.program[vue->cpu.inst.reg2];
uint32_t right = vue->cpu.program[vue->cpu.inst.reg1];
uint32_t result;
@ -691,13 +691,13 @@ static void cpuDIVU(VUE *vue) {
vue->cpu.program[vue->cpu.inst.reg1]
/* Multiply Halfword */
static void cpuMPYHW(VUE *vue) {
static void cpuMPYHW(Vue *vue) {
int32_t right = vue->cpu.program[vue->cpu.inst.reg1];
vue->cpu.program[vue->cpu.inst.reg2] *= SIGN_EXTEND(17, right);
}
/* Multiply */
static void cpuMUL(VUE *vue) {
static void cpuMUL(Vue *vue) {
int64_t full = (int64_t) vue->cpu.program[vue->cpu.inst.reg2] *
(int64_t) vue->cpu.program[vue->cpu.inst.reg1];
int32_t lower = (int32_t) full;
@ -715,7 +715,7 @@ static void cpuMUL(VUE *vue) {
cpuFloat(vue->cpu.program[vue->cpu.inst.reg1]))
/* Multiply Unsigned */
static void cpuMULU(VUE *vue) {
static void cpuMULU(Vue *vue) {
uint64_t full = (uint64_t)(uint32_t) vue->cpu.program[vue->cpu.inst.reg2] *
(uint64_t)(uint32_t) vue->cpu.program[vue->cpu.inst.reg1];
int32_t lower = (int32_t) full;
@ -760,7 +760,7 @@ static void cpuMULU(VUE *vue) {
vue->cpu.inst.imm)
/* Return from Trap or Interrupt */
static void cpuRETI(VUE *vue) {
static void cpuRETI(Vue *vue) {
if (vue->cpu.psw_np) {
vue->cpu.pc = vue->cpu.fepc;
cpuSetSystemRegister(vue, VUE_PSW, vue->cpu.fepsw, VUE_FALSE);
@ -810,7 +810,7 @@ static void cpuRETI(VUE *vue) {
vue->cpu.program[vue->cpu.inst.reg1])
/* Reverse Bits in Word */
static void cpuREV(VUE *vue) {
static void cpuREV(Vue *vue) {
int32_t value = vue->cpu.program[vue->cpu.inst.reg1];
value = (value >> 16 & 0x0000FFFF) | value << 16;
value = (value >> 8 & 0x00FF00FF) | (value << 8 & 0xFF00FF00);
@ -856,14 +856,14 @@ static void cpuREV(VUE *vue) {
cpuFloatConvert(vue, VUE_FALSE)
/* Exchange Byte */
static void cpuXB(VUE *vue) {
static void cpuXB(Vue *vue) {
int32_t value = vue->cpu.program[vue->cpu.inst.reg2];
vue->cpu.program[vue->cpu.inst.reg2] =
(value & 0xFFFF0000) | (value >> 8 & 0xFF) | (value & 0xFF) << 8;
}
/* Exchange Halfword */
static void cpuXH(VUE *vue) {
static void cpuXH(Vue *vue) {
int32_t value = vue->cpu.program[vue->cpu.inst.reg2];
vue->cpu.program[vue->cpu.inst.reg2] =
(value >> 16 & 0xFFFF) | value << 16;
@ -886,7 +886,7 @@ static void cpuXH(VUE *vue) {
*****************************************************************************/
/* Decode an instruction from its binary encoding */
static void cpuDecode(VUE_INSTRUCTION *inst) {
static void cpuDecode(VueInstruction *inst) {
int8_t extend; /* Sign-extend the immediate operand */
int32_t x; /* Working variable */
@ -945,7 +945,7 @@ static void cpuDecode(VUE_INSTRUCTION *inst) {
}
/* Check for an exception or interrupt */
static vbool cpuTestException(VUE *vue) {
static vbool cpuTestException(Vue *vue) {
int32_t level; /* Interrupt level */
/* Check for an interrupt */
@ -968,7 +968,7 @@ static vbool cpuTestException(VUE *vue) {
}
/* Operations for execute stage */
static vbool cpuExecute(VUE *vue) {
static vbool cpuExecute(Vue *vue) {
/* Application callback */
if (vue->onExecute != NULL) {
@ -1080,7 +1080,7 @@ static int32_t cpuSize(int32_t opcode) {
}
/* Operations for fetch stage */
static vbool cpuFetch(VUE *vue) {
static vbool cpuFetch(Vue *vue) {
/* Read the bits from the bus */
if (cpuRead(vue, vue->cpu.pc + (vue->cpu.fetch << 1),
@ -1109,7 +1109,7 @@ static vbool cpuFetch(VUE *vue) {
}
/* Operations for exception stage */
static vbool cpuException(VUE *vue) {
static vbool cpuException(Vue *vue) {
vbool isIRQ; /* The exception is an interrupt */
int32_t psw; /* Current value of PSW */
@ -1172,7 +1172,7 @@ static vbool cpuException(VUE *vue) {
}
/* Process the simulation */
static void cpuEmulate(VUE *vue, int32_t cycles) {
static void cpuEmulate(Vue *vue, int32_t cycles) {
/* The CPU is in permanent halt */
if (vue->cpu.stage == CPU_FATAL)
@ -1202,7 +1202,7 @@ vue->cpu.cycles = 0; /* DEBUG: Stop processing after execute */
}
/* System reset */
static void cpuReset(VUE *vue) {
static void cpuReset(Vue *vue) {
int32_t x;
/* Configure instance fields */
@ -1229,7 +1229,7 @@ static void cpuReset(VUE *vue) {
}
/* Determine the number of CPU cycles until something can happen */
static int32_t cpuUntil(VUE *vue, int32_t cycles) {
static int32_t cpuUntil(Vue *vue, int32_t cycles) {
if (vue->cpu.stage == CPU_FATAL || vue->cpu.stage == CPU_HALT)
return cycles;
return cycles < 0 ? vue->cpu.cycles :

View File

@ -6,7 +6,7 @@
*****************************************************************************/
/* System reset */
static void pakReset(VUE *vue) {
static void pakReset(Vue *vue) {
vue->pak.wcr_exp1w = 0;
vue->pak.wcr_rom1w = 0;
}

View File

@ -141,7 +141,7 @@ extern "C" {
*****************************************************************************/
/* Forward references */
typedef struct VUE VUE;
typedef struct Vue Vue;
/* Boolean */
typedef int vbool;
@ -152,12 +152,12 @@ typedef struct {
int32_t value; /* Value read/to write */
int8_t fetch; /* Index of machine code unit */
int8_t type; /* Data type */
} VUE_ACCESS;
} VueAccess;
/* Exception state */
typedef struct {
uint16_t code; /* Exception code */
} VUE_EXCEPTION;
} VueException;
/* Instruction state */
typedef struct {
@ -172,36 +172,36 @@ typedef struct {
uint8_t reg2; /* Destination/left register */
uint8_t size; /* Number of bytes in encoding */
uint8_t subopcode; /* Instruction subopcode */
} VUE_INSTRUCTION;
} VueInstruction;
/* Callbacks */
typedef int32_t (*VUE_ONEXCEPTION)(VUE *, VUE_EXCEPTION *);
typedef int32_t (*VUE_ONEXECUTE )(VUE *, VUE_INSTRUCTION *);
typedef int32_t (*VUE_ONREAD )(VUE *, VUE_ACCESS *);
typedef int32_t (*VUE_ONWRITE )(VUE *, VUE_ACCESS *);
typedef int32_t (*VueOnException)(Vue *, VueException *);
typedef int32_t (*VueOnExecute )(Vue *, VueInstruction *);
typedef int32_t (*VueOnRead )(Vue *, VueAccess *);
typedef int32_t (*VueOnWrite )(Vue *, VueAccess *);
/* Emulation state */
struct VUE {
struct Vue {
int32_t breakCode; /* Application break code */
uint8_t wram[0x10000]; /* System memory */
/* Callback handlers */
VUE_ONEXCEPTION onException;
VUE_ONEXECUTE onExecute;
VUE_ONREAD onRead;
VUE_ONWRITE onWrite;
VueOnException onException;
VueOnExecute onExecute;
VueOnRead onRead;
VueOnWrite onWrite;
/* CPU state */
struct {
VUE_ACCESS access; /* Access state */
VUE_EXCEPTION exception; /* Exception state */
VUE_INSTRUCTION inst; /* Instruction state */
int32_t cycles; /* Cycles until next stage */
int32_t jumpFrom[3]; /* Source PCs of most recent jumps */
int32_t jumpTo [3]; /* Destination PCs of most recent jumps */
uint16_t irq; /* Interrupt lines */
int fetch; /* Fetch unit index */
int stage; /* Current processing stage */
VueAccess access; /* Access state */
VueException exception; /* Exception state */
VueInstruction inst; /* Instruction state */
int32_t cycles; /* Cycles until next stage */
int32_t jumpFrom[3]; /* Source PCs of most recent jumps */
int32_t jumpTo [3]; /* Destination PCs of most recent jumps */
uint16_t irq; /* Interrupt lines */
int fetch; /* Fetch unit index */
int stage; /* Current processing stage */
/* Program registers */
int32_t program[32];
@ -265,21 +265,21 @@ struct VUE {
* Function Prototypes *
*****************************************************************************/
VUEAPI int32_t vueEmulate (VUE *vue, int32_t maxCycles);
VUEAPI int32_t vueGetBreakCode(VUE *vue);
VUEAPI int32_t vueGetRegister (VUE *vue, int32_t index, vbool system);
VUEAPI void vueInitialize (VUE *vue);
VUEAPI int32_t vueRead (VUE *vue, uint32_t address, int32_t type);
VUEAPI vbool vueReadBytes (VUE *vue, uint32_t address, uint8_t *dest, uint32_t length);
VUEAPI void vueReset (VUE *vue);
VUEAPI void vueSetException(VUE *vue, VUE_ONEXCEPTION callback);
VUEAPI void vueSetExecute (VUE *vue, VUE_ONEXECUTE callback);
VUEAPI void vueSetRead (VUE *vue, VUE_ONREAD callback);
VUEAPI int32_t vueSetRegister (VUE *vue, int32_t index, vbool system, int32_t value);
VUEAPI vbool vueSetROM (VUE *vue, uint8_t *rom, uint32_t size);
VUEAPI void vueSetWrite (VUE *vue, VUE_ONWRITE callback);
VUEAPI void vueWrite (VUE *vue, uint32_t address, int32_t type, int32_t value);
VUEAPI vbool vueWriteBytes (VUE *vue, uint32_t address, uint8_t *src, uint32_t length);
VUEAPI int32_t vueEmulate (Vue *vue, int32_t maxCycles);
VUEAPI int32_t vueGetBreakCode(Vue *vue);
VUEAPI int32_t vueGetRegister (Vue *vue, int32_t index, vbool system);
VUEAPI void vueInitialize (Vue *vue);
VUEAPI int32_t vueRead (Vue *vue, uint32_t address, int32_t type);
VUEAPI vbool vueReadBytes (Vue *vue, uint32_t address, uint8_t *dest, uint32_t length);
VUEAPI void vueReset (Vue *vue);
VUEAPI void vueSetException(Vue *vue, VueOnException callback);
VUEAPI void vueSetExecute (Vue *vue, VueOnExecute callback);
VUEAPI void vueSetRead (Vue *vue, VueOnRead callback);
VUEAPI int32_t vueSetRegister (Vue *vue, int32_t index, vbool system, int32_t value);
VUEAPI vbool vueSetROM (Vue *vue, uint8_t *rom, uint32_t size);
VUEAPI void vueSetWrite (Vue *vue, VueOnWrite callback);
VUEAPI void vueWrite (Vue *vue, uint32_t address, int32_t type, int32_t value);
VUEAPI vbool vueWriteBytes (Vue *vue, uint32_t address, uint8_t *src, uint32_t length);

View File

@ -155,7 +155,7 @@ static void writeBytes(uint8_t *data, uint32_t datlen, uint32_t address,
*****************************************************************************/
/* Process the simulation */
int32_t vueEmulate(VUE *vue, int32_t maxCycles) {
int32_t vueEmulate(Vue *vue, int32_t maxCycles) {
int32_t cycles; /* Number of cycles to process */
/* Process up to the given number of cycles */
@ -200,12 +200,12 @@ int32_t vueEmulate(VUE *vue, int32_t maxCycles) {
}
/* Retrieve the application break code */
int32_t vueGetBreakCode(VUE *vue) {
int32_t vueGetBreakCode(Vue *vue) {
return vue == NULL ? 0 : vue->breakCode;
}
/* Retrieve the value of a register */
int32_t vueGetRegister(VUE *vue, int32_t index, vbool system) {
int32_t vueGetRegister(Vue *vue, int32_t index, vbool system) {
/* Error checking */
if (vue == NULL)
@ -229,7 +229,7 @@ int32_t vueGetRegister(VUE *vue, int32_t index, vbool system) {
}
/* Prepare an emulation state context for use */
void vueInitialize(VUE *vue) {
void vueInitialize(Vue *vue) {
if (vue == NULL)
return;
vue->onException = NULL;
@ -241,7 +241,7 @@ void vueInitialize(VUE *vue) {
}
/* Read a value from the CPU bus */
int32_t vueRead(VUE *vue, uint32_t address, int32_t type) {
int32_t vueRead(Vue *vue, uint32_t address, int32_t type) {
/* Error checking */
if (vue == NULL)
@ -257,7 +257,7 @@ int32_t vueRead(VUE *vue, uint32_t address, int32_t type) {
}
/* Read bytes from the CPU bus */
vbool vueReadBytes(VUE *vue, uint32_t address, uint8_t *dest, uint32_t length){
vbool vueReadBytes(Vue *vue, uint32_t address, uint8_t *dest, uint32_t length){
uint32_t count; /* Bytes to read in one iteration */
/* Error checking */
@ -289,7 +289,7 @@ vbool vueReadBytes(VUE *vue, uint32_t address, uint8_t *dest, uint32_t length){
}
/* Initialize all system components */
void vueReset(VUE *vue) {
void vueReset(Vue *vue) {
uint32_t x; /* Iterator */
/* Error checking */
@ -304,25 +304,25 @@ void vueReset(VUE *vue) {
}
/* Specify an exception breakpoint callback */
void vueSetException(VUE *vue, VUE_ONEXCEPTION callback) {
void vueSetException(Vue *vue, VueOnException callback) {
if (vue != NULL)
vue->onException = callback;
}
/* Specify an execute breakpoint callback */
void vueSetExecute(VUE *vue, VUE_ONEXECUTE callback) {
void vueSetExecute(Vue *vue, VueOnExecute callback) {
if (vue != NULL)
vue->onExecute = callback;
}
/* Specify a read breakpoint callback */
void vueSetRead(VUE *vue, VUE_ONREAD callback) {
void vueSetRead(Vue *vue, VueOnRead callback) {
if (vue != NULL)
vue->onRead = callback;
}
/* Specify a value for a register */
int32_t vueSetRegister(VUE *vue, int32_t index, vbool system, int32_t value) {
int32_t vueSetRegister(Vue *vue, int32_t index, vbool system, int32_t value) {
return vue == NULL ? 0 :
index == VUE_PC && system ? vue->cpu.pc = value & 0xFFFFFFFE :
index < 0 || index > 31 ? 0 :
@ -332,7 +332,7 @@ int32_t vueSetRegister(VUE *vue, int32_t index, vbool system, int32_t value) {
}
/* Specify a new ROM buffer */
vbool vueSetROM(VUE *vue, uint8_t *rom, uint32_t size) {
vbool vueSetROM(Vue *vue, uint8_t *rom, uint32_t size) {
/* Error checking */
if (
@ -349,13 +349,13 @@ vbool vueSetROM(VUE *vue, uint8_t *rom, uint32_t size) {
}
/* Specify a write breakpoint callback */
void vueSetWrite(VUE *vue, VUE_ONREAD callback) {
void vueSetWrite(Vue *vue, VueOnRead callback) {
if (vue != NULL)
vue->onWrite = callback;
}
/* Write a value to the CPU bus */
void vueWrite(VUE *vue, uint32_t address, int32_t type, int32_t value) {
void vueWrite(Vue *vue, uint32_t address, int32_t type, int32_t value) {
/* Error checking */
if (vue == NULL)
@ -374,7 +374,7 @@ void vueWrite(VUE *vue, uint32_t address, int32_t type, int32_t value) {
}
/* Write bytes to the CPU bus */
vbool vueWriteBytes(VUE *vue, uint32_t address, uint8_t *src, uint32_t length){
vbool vueWriteBytes(Vue *vue, uint32_t address, uint8_t *src, uint32_t length){
uint32_t count; /* Bytes to write in one iteration */
/* Error checking */

View File

@ -35,7 +35,7 @@ public class Main {
// Load the native object file into the JVM
try {
System.load(file.getAbsolutePath());
VUE.setNativeID(filename.substring(0,
Vue.setNativeID(filename.substring(0,
filename.lastIndexOf(".")));
break;
}

View File

@ -74,7 +74,7 @@ public class App {
// Specify whether using the native module
boolean setUseNative(boolean useNative) {
return this.useNative = useNative && VUE.isNativeLoaded();
return this.useNative = useNative && Vue.isNativeLoaded();
}

View File

@ -157,7 +157,7 @@ class Disassembler {
;
// Bcond mnemonic
if (inst.id == VUE.BCOND && bcondCombine) {
if (inst.id == Vue.BCOND && bcondCombine) {
row.mnemonic = "B" + CONDITIONS[inst.cond];
if (lower && (inst.cond & 7) == 1)
row.mnemonic = inst.cond == 1 ? "BL" : "BNL";
@ -168,7 +168,7 @@ class Disassembler {
}
// SETF mnemonic
else if (inst.id == VUE.SETF && setfCombine)
else if (inst.id == Vue.SETF && setfCombine)
row.mnemonic = "SETF" + CONDITIONS[inst.imm];
// All other mnemonics
@ -180,7 +180,7 @@ class Disassembler {
// Operands by format
row.operands = null;
if (inst.id != VUE.ILLEGAL) switch (inst.format) {
if (inst.id != Vue.ILLEGAL) switch (inst.format) {
case 1: // Fallthrough
case 7: row.operands = formatI_VII(inst ); break;
case 2: row.operands = formatII (inst ); break;
@ -211,10 +211,10 @@ class Disassembler {
// One-operand instructions
switch (inst.id) {
case VUE.JMP:
case Vue.JMP:
return String.format(jmpBrackets ? "[%s]" : "%s", reg1);
case VUE.XB: // Fallthrough
case VUE.XH:
case Vue.XB: // Fallthrough
case Vue.XH:
return reg2;
}
@ -236,34 +236,34 @@ class Disassembler {
switch (inst.id) {
// Zero-operand
case VUE.CLI : // Fallthrough
case VUE.HALT: // Fallthrough
case VUE.RETI: // Fallthrough
case VUE.SEI :
case Vue.CLI : // Fallthrough
case Vue.HALT: // Fallthrough
case Vue.RETI: // Fallthrough
case Vue.SEI :
return null;
// One-operand
case VUE.TRAP:
case Vue.TRAP:
return Integer.toString(inst.imm);
}
// Combined SETF
String reg2 = program(inst.reg2);
if (inst.id == VUE.SETF && setfCombine)
if (inst.id == Vue.SETF && setfCombine)
return reg2;
// Two-operand instructions
String imm = String.format("%s%d", immNumber ? "#" : "", inst.imm);
switch (inst.id) {
case VUE.LDSR: // Fallthrough
case VUE.STSR:
case Vue.LDSR: // Fallthrough
case Vue.STSR:
if (!systemNames || SYSTEMS[inst.imm] == null)
break;
imm = SYSTEMS[inst.imm];
if (!systemCaps)
imm = imm.toLowerCase();
break;
case VUE.SETF:
case Vue.SETF:
if (!setfNames)
break;
imm = CONDITIONS[inst.imm];
@ -273,7 +273,7 @@ class Disassembler {
}
// LDSR
if (inst.id == VUE.LDSR) {
if (inst.id == Vue.LDSR) {
String temp = imm;
imm = reg2;
reg2 = temp;
@ -313,8 +313,8 @@ class Disassembler {
String reg1 = program(inst.reg1);
String reg2 = program(inst.reg2);
String imm = toHex(
inst.id == VUE.MOVEA ? inst.imm & 0xFFFF : inst.imm,
inst.id == VUE.ADDI ? 1 : 4,
inst.id == Vue.MOVEA ? inst.imm & 0xFFFF : inst.imm,
inst.id == Vue.ADDI ? 1 : 4,
immNumber
);
return String.format("%s, %s, %s",
@ -345,12 +345,12 @@ class Disassembler {
// Write instruction
switch (inst.id) {
case VUE.OUT_B: // Fallthrough
case VUE.OUT_H: // Fallthrough
case VUE.OUT_W: // Fallthrough
case VUE.ST_B : // Fallthrough
case VUE.ST_H : // Fallthrough
case VUE.ST_W :
case Vue.OUT_B: // Fallthrough
case Vue.OUT_H: // Fallthrough
case Vue.OUT_W: // Fallthrough
case Vue.ST_B : // Fallthrough
case Vue.ST_H : // Fallthrough
case Vue.ST_W :
String temp = src;
src = dest;
dest = temp;

View File

@ -125,7 +125,7 @@ class DisassemblerPane extends JScrollPane {
case KeyEvent.VK_F11:
parent.parent.vue.emulate(0);
parent.parent.refreshDebug();
int pc = parent.parent.vue.getRegister(VUE.PC, true);
int pc = parent.parent.vue.getRegister(Vue.PC, true);
if (!isVisible(pc))
seek(pc, count / 3);
break;
@ -136,7 +136,7 @@ class DisassemblerPane extends JScrollPane {
// Client paint
private void onPaint(Graphics2D g, int width, int height) {
var vue = parent.parent.vue;
int pc = vue.getRegister(VUE.PC, true);
int pc = vue.getRegister(Vue.PC, true);
// The view is being shown for the first time
if (!shown) {
@ -252,7 +252,7 @@ class DisassemblerPane extends JScrollPane {
var data = new byte[count * 4];
int offset = 0;
var vue = parent.parent.vue;
int pc = vue.getRegister(VUE.PC, true);
int pc = vue.getRegister(Vue.PC, true);
target &= 0xFFFFFFFE;
// Load enough bytes to represent every fully visible instruction
@ -283,7 +283,7 @@ class DisassemblerPane extends JScrollPane {
var data = new byte[(Math.abs(row) + 9) * 4];
int offset = 0;
var vue = parent.parent.vue;
int pc = vue.getRegister(VUE.PC, true);
int pc = vue.getRegister(Vue.PC, true);
target &= 0xFFFFFFFE;
// Scrolling down

View File

@ -16,7 +16,7 @@ class MainWindow extends JFrame {
// Instance fields
App app; // Containing application
VUE vue; // Emulation core context
Vue vue; // Emulation core context
// Private fields
private boolean debugMode; // Window is in debug mode
@ -64,9 +64,9 @@ class MainWindow extends JFrame {
// Configure instance fields
this.app = app;
pwd = Util.PWD;
vue = VUE.create(app.getUseNative());
vue = Vue.create(app.getUseNative());
System.out.println("Native: " +
(vue.isNative() ? VUE.getNativeID() : "No"));
(vue.isNative() ? Vue.getNativeID() : "No"));
// Configure video pane
video = new JPanel(null) {

View File

@ -117,17 +117,17 @@ class Register {
// Expansion controls
switch (type) {
case PROGRAM : initProgram(); break;
case VUE.CHCW: initCHCW (); break;
case VUE.ECR : initECR (); break;
case VUE.PC : initPC (); break;
case VUE.PIR : initPIR (); break;
case VUE.PSW : initPSW (); break;
case VUE.TKCW: initTKCW (); break;
case Vue.CHCW: initCHCW (); break;
case Vue.ECR : initECR (); break;
case Vue.PC : initPC (); break;
case Vue.PIR : initPIR (); break;
case Vue.PSW : initPSW (); break;
case Vue.TKCW: initTKCW (); break;
default: return;
}
// Expansion indentation
if (index != VUE.PC) {
if (index != Vue.PC) {
indent = new JPanel(null);
indent.setOpaque(false);
indent.setPreferredSize(new Dimension(0, 0));
@ -141,7 +141,7 @@ class Register {
expansion.setVisible(false);
gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.WEST;
if (index == VUE.PC)
if (index == Vue.PC)
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.insets = new Insets(0, 4, 0, 0);
@ -149,7 +149,7 @@ class Register {
parent.add(gbc, expansion);
// Handling for PSW
if (index == VUE.PSW && type == VUE.PSW)
if (index == Vue.PSW && type == Vue.PSW)
setExpanded(true);
}
@ -213,7 +213,7 @@ class Register {
parent.requestFocus();
});
txt.putClientProperty("index",
x == 0 ? VUE.JUMP_FROM : VUE.JUMP_TO);
x == 0 ? Vue.JUMP_FROM : Vue.JUMP_TO);
txt.setBorder(null);
txt.setOpaque(false);
gbc = new GridBagConstraints();
@ -309,9 +309,9 @@ class Register {
for (var ctrl : controls) {
if (!(ctrl instanceof JTextField))
continue;
if (type == VUE.PC || (Boolean) ctrl.getClientProperty("hex"))
if (type == Vue.PC || (Boolean) ctrl.getClientProperty("hex"))
((JTextField) ctrl).setFont(CPUWindow.regHexFont);
int digits = type == VUE.PC ? 8 :
int digits = type == Vue.PC ? 8 :
(Integer) ctrl.getClientProperty("digits");
size = ctrl.getPreferredSize();
size.width = digits * fontSize.width + 4;
@ -351,7 +351,7 @@ class Register {
int val; // The value to be displayed
// Jump history
if (type == VUE.PC) {
if (type == Vue.PC) {
digits = 8;
hex = true;
val = vue.getRegister((Integer)
@ -388,7 +388,7 @@ class Register {
// Update controls
this.expanded = expanded;
btnExpand.setText(expanded ? "-" : "+");
if (type != VUE.PC)
if (type != Vue.PC)
indent.setVisible(expanded);
expansion.setVisible(expanded);
parent.revalidate();
@ -504,8 +504,8 @@ class Register {
private void setValue(int value) {
parent.parent.parent.vue.setRegister(index, type != PROGRAM, value);
refresh();
if (index == VUE.PSW && type == VUE.PSW)
parent.registers.get(VUE.PC).refresh();
if (index == Vue.PSW && type == Vue.PSW)
parent.registers.get(Vue.PC).refresh();
}
}

View File

@ -55,17 +55,17 @@ class RegisterList extends JScrollPane {
// Initialize system registers
if (system) {
new Register(this, "PC" , VUE.PC , VUE.PC );
new Register(this, "PSW" , VUE.PSW , VUE.PSW );
new Register(this, "EIPC" , VUE.EIPC , Register.PLAIN);
new Register(this, "EIPSW", VUE.EIPSW, VUE.PSW );
new Register(this, "FEPC" , VUE.FEPC , Register.PLAIN);
new Register(this, "FEPSW", VUE.FEPSW, VUE.PSW );
new Register(this, "ECR" , VUE.ECR , VUE.ECR );
new Register(this, "ADTRE", VUE.ADTRE, Register.PLAIN);
new Register(this, "CHCW" , VUE.CHCW , VUE.CHCW );
new Register(this, "PIR" , VUE.PIR , VUE.PIR );
new Register(this, "TKCW" , VUE.TKCW , VUE.TKCW );
new Register(this, "PC" , Vue.PC , Vue.PC );
new Register(this, "PSW" , Vue.PSW , Vue.PSW );
new Register(this, "EIPC" , Vue.EIPC , Register.PLAIN);
new Register(this, "EIPSW", Vue.EIPSW, Vue.PSW );
new Register(this, "FEPC" , Vue.FEPC , Register.PLAIN);
new Register(this, "FEPSW", Vue.FEPSW, Vue.PSW );
new Register(this, "ECR" , Vue.ECR , Vue.ECR );
new Register(this, "ADTRE", Vue.ADTRE, Register.PLAIN);
new Register(this, "CHCW" , Vue.CHCW , Vue.CHCW );
new Register(this, "PIR" , Vue.PIR , Vue.PIR );
new Register(this, "TKCW" , Vue.TKCW , Vue.TKCW );
new Register(this, "29" , 29, Register.PLAIN);
new Register(this, "30" , 30, Register.PLAIN);
new Register(this, "31" , 31, Register.PLAIN);
@ -75,11 +75,11 @@ class RegisterList extends JScrollPane {
else for (int x = 0; x < 32; x++) {
String name = null;
switch (x) {
case VUE.GP: name = "gp"; break;
case VUE.HP: name = "hp"; break;
case VUE.LP: name = "lp"; break;
case VUE.SP: name = "sp"; break;
case VUE.TP: name = "tp"; break;
case Vue.GP: name = "gp"; break;
case Vue.HP: name = "hp"; break;
case Vue.LP: name = "lp"; break;
case Vue.SP: name = "sp"; break;
case Vue.TP: name = "tp"; break;
}
new Register(this, name, x, Register.PROGRAM);
}

View File

@ -609,7 +609,7 @@ static void evalUnary(VUE *vue, int32_t id, int32_t *stack, int32_t size) {
}
// Evaluate a breakpoint condition for an emulation context
int32_t evaluate(VUE *vue, BREAKPOINT *brk, int32_t *stack) {
int32_t evaluate(VUE *vue, Breakpoint *brk, int32_t *stack) {
// The condition is empty
if (brk->numCondition == 0)

View File

@ -233,15 +233,15 @@ public class Breakpoint {
SYMDEFS.put("lp" , 131);
// System register symbol definitions
SYMDEFS.put("adtre", 200 + VUE.ADTRE);
SYMDEFS.put("chcw" , 200 + VUE.CHCW );
SYMDEFS.put("ecr" , 200 + VUE.ECR );
SYMDEFS.put("eipc" , 200 + VUE.EIPC );
SYMDEFS.put("eipsw", 200 + VUE.EIPSW);
SYMDEFS.put("fepc" , 200 + VUE.FEPC );
SYMDEFS.put("fepsw", 200 + VUE.FEPSW);
SYMDEFS.put("pc" , VUE.PC );
SYMDEFS.put("psw" , 200 + VUE.PSW );
SYMDEFS.put("adtre", 200 + Vue.ADTRE);
SYMDEFS.put("chcw" , 200 + Vue.CHCW );
SYMDEFS.put("ecr" , 200 + Vue.ECR );
SYMDEFS.put("eipc" , 200 + Vue.EIPC );
SYMDEFS.put("eipsw", 200 + Vue.EIPSW);
SYMDEFS.put("fepc" , 200 + Vue.FEPC );
SYMDEFS.put("fepsw", 200 + Vue.FEPSW);
SYMDEFS.put("pc" , Vue.PC );
SYMDEFS.put("psw" , 200 + Vue.PSW );
SYMDEFS.put("sr29" , 229 );
SYMDEFS.put("sr31" , 231 );
LITDEFS.put("pir" , 0x00005346);
@ -478,7 +478,7 @@ public class Breakpoint {
///////////////////////////////////////////////////////////////////////////
// Evaluate the condition for an emulation context
boolean evaluate(JavaVUE vue, int[] stack) {
boolean evaluate(JavaVue vue, int[] stack) {
// The condition is empty
if (tokens.length == 0)
@ -994,9 +994,9 @@ public class Breakpoint {
}
// Evaluate a functional symbol
private static int evalSymbol(JavaVUE vue, int id, int[] stack, int size) {
private static int evalSymbol(JavaVue vue, int id, int[] stack, int size) {
int ret = 0;
if (id == VUE.PC)
if (id == Vue.PC)
ret = vue.cpu.pc;
else if (id >= 200)
ret = vue.cpu.getSystemRegister(id - 200);
@ -1026,7 +1026,7 @@ public class Breakpoint {
}
// Evaluate a unary operator
private static void evalUnary(JavaVUE vue, int id, int[] stack, int size) {
private static void evalUnary(JavaVue vue, int id, int[] stack, int size) {
int type = stack[size - 2];
int value = stack[size - 1];
boolean isWord = type == WORD;
@ -1253,31 +1253,31 @@ public class Breakpoint {
///////////////////////////////////////////////////////////////////////////
// Evaluate address
private static int evalAddress(JavaVUE vue) {
private static int evalAddress(JavaVue vue) {
if (vue.cpu.inst.format == 6)
return vue.cpu.program[vue.cpu.inst.reg1] + vue.cpu.inst.disp;
switch (vue.cpu.inst.id) {
case VUE.BCOND: case VUE.JAL: case VUE.JMP: case VUE.JR:
case Vue.BCOND: case Vue.JAL: case Vue.JMP: case Vue.JR:
return vue.cpu.pc + vue.cpu.inst.disp;
case VUE.RETI:
case Vue.RETI:
return vue.cpu.psw_np != 0 ? vue.cpu.fepc : vue.cpu.eipc;
case VUE.TRAP:
case Vue.TRAP:
return 0xFFFFFFA0 + vue.cpu.inst.imm & 0xFFFFFFF0;
}
return 0;
}
// Evaluate cond
private static int evalCond(JavaVUE vue) {
private static int evalCond(JavaVue vue) {
switch (vue.cpu.inst.id) {
case VUE.BCOND: return vue.cpu.inst.cond;
case VUE.SETF : return vue.cpu.inst.imm;
case Vue.BCOND: return vue.cpu.inst.cond;
case Vue.SETF : return vue.cpu.inst.imm;
}
return 0;
}
// Evaluate disp
private static int evalDisp(JavaVUE vue) {
private static int evalDisp(JavaVue vue) {
switch (vue.cpu.inst.format) {
case 3: case 4: case 6: return vue.cpu.inst.disp;
}
@ -1285,7 +1285,7 @@ public class Breakpoint {
}
// Evaluate imm
private static int evalImm(JavaVUE vue) {
private static int evalImm(JavaVue vue) {
switch (vue.cpu.inst.format) {
case 2: case 5: return vue.cpu.inst.imm;
}
@ -1293,7 +1293,7 @@ public class Breakpoint {
}
// Evaluate reg1
private static int evalReg1(JavaVUE vue) {
private static int evalReg1(JavaVue vue) {
switch (vue.cpu.inst.format) {
case 1: case 5: case 6: case 7: return vue.cpu.inst.reg1;
}
@ -1301,7 +1301,7 @@ public class Breakpoint {
}
// Evaluate reg2
private static int evalReg2(JavaVUE vue) {
private static int evalReg2(JavaVue vue) {
switch (vue.cpu.inst.format) {
case 1: case 2: case 5: case 6: case 7: return vue.cpu.inst.reg2;
}
@ -1309,15 +1309,15 @@ public class Breakpoint {
}
// Evaluate regid
private static int evalRegId(JavaVUE vue) {
private static int evalRegId(JavaVue vue) {
switch (vue.cpu.inst.id) {
case VUE.LDSR: case VUE.STSR: return vue.cpu.inst.imm;
case Vue.LDSR: case Vue.STSR: return vue.cpu.inst.imm;
}
return 0;
}
// Evaluate subopcode
private static int evalSubopcode(JavaVUE vue) {
private static int evalSubopcode(JavaVue vue) {
switch (vue.cpu.inst.opcode) {
case 0x1F: return vue.cpu.inst.imm;
case 0x3E: return vue.cpu.inst.subopcode;
@ -1326,13 +1326,13 @@ public class Breakpoint {
}
// Evaluate value
private static int evalValue(JavaVUE vue) {
private static int evalValue(JavaVue vue) {
return vue.cpu.inst.format == 6 ? vue.cpu.access.value : 0;
}
// Evaluate vector
private static int evalVector(JavaVUE vue) {
return vue.cpu.inst.id == VUE.TRAP ? vue.cpu.inst.imm : 0;
private static int evalVector(JavaVue vue) {
return vue.cpu.inst.id == Vue.TRAP ? vue.cpu.inst.imm : 0;
}
@ -1372,8 +1372,8 @@ public class Breakpoint {
}
// Evaluate []
private static int evalReadWord(boolean isWord, int value, JavaVUE vue) {
return vue.read(isWord ? value : toWord(asFloat(value)), VUE.S32);
private static int evalReadWord(boolean isWord, int value, JavaVue vue) {
return vue.read(isWord ? value : toWord(asFloat(value)), Vue.S32);
}
// Evaluate round

View File

@ -7,7 +7,7 @@ import java.util.*;
class CPU {
// Private fields
private JavaVUE vue; // Emulation state
private JavaVue vue; // Emulation state
// Package fields
Access access; // Access state
@ -95,7 +95,7 @@ class CPU {
///////////////////////////////////////////////////////////////////////////
// Default constructor
CPU(JavaVUE vue) {
CPU(JavaVue vue) {
access = new Access();
exception = new Ecxeption();
inst = new Instruction();
@ -144,19 +144,19 @@ this.cycles = 0; // DEBUG: Stop processing after execute
// Read a system register
int getSystemRegister(int index) {
switch (index) {
case VUE.ADTRE: return adtre;
case VUE.EIPC : return eipc;
case VUE.EIPSW: return eipsw;
case VUE.FEPC : return fepc;
case VUE.FEPSW: return fepsw;
case VUE.ECR : return ecr_fecc << 16 | ecr_eicc;
case VUE.PIR : return 0x00005346;
case VUE.TKCW : return 0x000000E0;
case VUE.CHCW : return chcw_ice << 1;
case Vue.ADTRE: return adtre;
case Vue.EIPC : return eipc;
case Vue.EIPSW: return eipsw;
case Vue.FEPC : return fepc;
case Vue.FEPSW: return fepsw;
case Vue.ECR : return ecr_fecc << 16 | ecr_eicc;
case Vue.PIR : return 0x00005346;
case Vue.TKCW : return 0x000000E0;
case Vue.CHCW : return chcw_ice << 1;
case 29 : return sr29;
case 30 : return 0x00000004;
case 31 : return sr31;
case VUE.PSW : return
case Vue.PSW : return
psw_i << 16 | psw_fro << 9 | psw_fpr << 4 |
psw_np << 15 | psw_fiv << 8 | psw_cy << 3 |
psw_ep << 14 | psw_fzd << 7 | psw_ov << 2 |
@ -201,22 +201,22 @@ this.cycles = 0; // DEBUG: Stop processing after execute
// Write a system register
int setSystemRegister(int index, int value, boolean debug) {
switch (index) {
case VUE.ADTRE: return adtre = value & 0xFFFFFFFE;
case VUE.EIPC : return eipc = value & 0xFFFFFFFE;
case VUE.EIPSW: return eipsw = value & 0x000FF3FF;
case VUE.FEPC : return fepc = value & 0xFFFFFFFE;
case VUE.FEPSW: return fepsw = value & 0x000FF3FF;
case Vue.ADTRE: return adtre = value & 0xFFFFFFFE;
case Vue.EIPC : return eipc = value & 0xFFFFFFFE;
case Vue.EIPSW: return eipsw = value & 0x000FF3FF;
case Vue.FEPC : return fepc = value & 0xFFFFFFFE;
case Vue.FEPSW: return fepsw = value & 0x000FF3FF;
case 29 : return sr29 = value;
case 31 : return sr31 = debug || value >= 0 ? value : -value;
case VUE.ECR:
case Vue.ECR:
if (debug) {
ecr_fecc = value >> 16 & 0xFFFF;
ecr_eicc = value & 0xFFFF;
}
return ecr_fecc << 16 | ecr_eicc;
case VUE.CHCW :
case Vue.CHCW :
chcw_cen = value >> 20 & 0x00000FFF;
chcw_cec = value >> 8 & 0x00000FFF;
chcw_sa = value >> 8 & 0x00FFFFFF;
@ -235,7 +235,7 @@ this.cycles = 0; // DEBUG: Stop processing after execute
return chcw_ice << 1;
case VUE.PSW :
case Vue.PSW :
psw_i = value >> 16 & 15; psw_fov = value >> 6 & 1;
psw_np = value >> 15 & 1; psw_fud = value >> 5 & 1;
psw_ep = value >> 14 & 1; psw_fpr = value >> 4 & 1;
@ -282,13 +282,13 @@ this.cycles = 0; // DEBUG: Stop processing after execute
// Configure working variables
exception.code &= 0xFFFF;
boolean isIRQ = (exception.code & 0xFF00) == 0xFE00;
int psw = getSystemRegister(VUE.PSW);
int psw = getSystemRegister(Vue.PSW);
// Fatal exception
if (psw_np != 0) {
vue.write(0x00000000, VUE.S32, 0xFFFF0000 | exception.code);
vue.write(0x00000004, VUE.S32, psw);
vue.write(0x00000008, VUE.S32, pc);
vue.write(0x00000000, Vue.S32, 0xFFFF0000 | exception.code);
vue.write(0x00000004, Vue.S32, psw);
vue.write(0x00000008, Vue.S32, pc);
stage = FATAL;
return true;
}
@ -341,82 +341,82 @@ this.cycles = 0; // DEBUG: Stop processing after execute
// Processing by instruction ID
switch (inst.id) {
case VUE.ADD_IMM: ADD_IMM(); break;
case VUE.ADD_REG: ADD_REG(); break;
case VUE.ADDF_S : ADDF_S (); break;
case VUE.ADDI : ADDI (); break;
case VUE.AND : AND (); break;
//case VUE.ANDBSU : ANDBSU (); break;
case VUE.ANDI : ANDI (); break;
//case VUE.ANDNBSU: ANDNBSU(); break;
case VUE.BCOND : BCOND (); break;
case VUE.CAXI : CAXI (); break;
case VUE.CLI : CLI (); break;
case VUE.CMP_IMM: CMP_IMM(); break;
case VUE.CMP_REG: CMP_REG(); break;
case VUE.CMPF_S : CMPF_S (); break;
case VUE.CVT_SW : CVT_SW (); break;
case VUE.CVT_WS : CVT_WS (); break;
case VUE.DIV : DIV (); break;
case VUE.DIVF_S : DIVF_S (); break;
case VUE.DIVU : DIVU (); break;
case VUE.HALT : HALT (); break;
case VUE.IN_B : IN_B (); break;
case VUE.IN_H : IN_H (); break;
case VUE.IN_W : IN_W (); break;
case VUE.JAL : JAL (); break;
case VUE.JMP : JMP (); break;
case VUE.JR : JR (); break;
case VUE.LD_B : LD_B (); break;
case VUE.LD_H : LD_H (); break;
case VUE.LD_W : LD_W (); break;
case VUE.LDSR : LDSR (); break;
case VUE.MOV_IMM: MOV_IMM(); break;
case VUE.MOV_REG: MOV_REG(); break;
//case VUE.MOVBSU : MOVBSU (); break;
case VUE.MOVEA : MOVEA (); break;
case VUE.MOVHI : MOVHI (); break;
case VUE.MPYHW : MPYHW (); break;
case VUE.MUL : MUL (); break;
case VUE.MULF_S : MULF_S (); break;
case VUE.MULU : MULU (); break;
case VUE.NOT : NOT (); break;
//case VUE.NOTBSU : NOTBSU (); break;
case VUE.OR : OR (); break;
//case VUE.ORBSU : ORBSU (); break;
case VUE.ORI : ORI (); break;
//case VUE.ORNBSU : ORNBSU (); break;
case VUE.OUT_B : OUT_B (); break;
case VUE.OUT_H : OUT_H (); break;
case VUE.OUT_W : OUT_W (); break;
case VUE.RETI : RETI (); break;
case VUE.REV : REV (); break;
case VUE.SAR_IMM: SAR_IMM(); break;
case VUE.SAR_REG: SAR_REG(); break;
//case VUE.SCH0BSD: SCH0BSD(); break;
//case VUE.SCH0BSU: SCH0BSU(); break;
//case VUE.SCH1BSD: SCH1BSD(); break;
//case VUE.SCH1BSU: SCH1BSU(); break;
case VUE.SEI : SEI (); break;
case VUE.SETF : SETF (); break;
case VUE.SHL_IMM: SHL_IMM(); break;
case VUE.SHL_REG: SHL_REG(); break;
case VUE.SHR_IMM: SHR_IMM(); break;
case VUE.SHR_REG: SHR_REG(); break;
case VUE.ST_B : ST_B (); break;
case VUE.ST_H : ST_H (); break;
case VUE.ST_W : ST_W (); break;
case VUE.STSR : STSR (); break;
case VUE.SUB : SUB (); break;
case VUE.SUBF_S : SUBF_S (); break;
case VUE.TRAP : TRAP (); break;
case VUE.TRNC_SW: TRNC_SW(); break;
case VUE.XB : XB (); break;
case VUE.XH : XH (); break;
case VUE.XOR : XOR (); break;
//case VUE.XORBSU : XORBSU (); break;
case VUE.XORI : XORI (); break;
//case VUE.XORNBSU: XORNBSU(); break;
case Vue.ADD_IMM: ADD_IMM(); break;
case Vue.ADD_REG: ADD_REG(); break;
case Vue.ADDF_S : ADDF_S (); break;
case Vue.ADDI : ADDI (); break;
case Vue.AND : AND (); break;
//case Vue.ANDBSU : ANDBSU (); break;
case Vue.ANDI : ANDI (); break;
//case Vue.ANDNBSU: ANDNBSU(); break;
case Vue.BCOND : BCOND (); break;
case Vue.CAXI : CAXI (); break;
case Vue.CLI : CLI (); break;
case Vue.CMP_IMM: CMP_IMM(); break;
case Vue.CMP_REG: CMP_REG(); break;
case Vue.CMPF_S : CMPF_S (); break;
case Vue.CVT_SW : CVT_SW (); break;
case Vue.CVT_WS : CVT_WS (); break;
case Vue.DIV : DIV (); break;
case Vue.DIVF_S : DIVF_S (); break;
case Vue.DIVU : DIVU (); break;
case Vue.HALT : HALT (); break;
case Vue.IN_B : IN_B (); break;
case Vue.IN_H : IN_H (); break;
case Vue.IN_W : IN_W (); break;
case Vue.JAL : JAL (); break;
case Vue.JMP : JMP (); break;
case Vue.JR : JR (); break;
case Vue.LD_B : LD_B (); break;
case Vue.LD_H : LD_H (); break;
case Vue.LD_W : LD_W (); break;
case Vue.LDSR : LDSR (); break;
case Vue.MOV_IMM: MOV_IMM(); break;
case Vue.MOV_REG: MOV_REG(); break;
//case Vue.MOVBSU : MOVBSU (); break;
case Vue.MOVEA : MOVEA (); break;
case Vue.MOVHI : MOVHI (); break;
case Vue.MPYHW : MPYHW (); break;
case Vue.MUL : MUL (); break;
case Vue.MULF_S : MULF_S (); break;
case Vue.MULU : MULU (); break;
case Vue.NOT : NOT (); break;
//case Vue.NOTBSU : NOTBSU (); break;
case Vue.OR : OR (); break;
//case Vue.ORBSU : ORBSU (); break;
case Vue.ORI : ORI (); break;
//case Vue.ORNBSU : ORNBSU (); break;
case Vue.OUT_B : OUT_B (); break;
case Vue.OUT_H : OUT_H (); break;
case Vue.OUT_W : OUT_W (); break;
case Vue.RETI : RETI (); break;
case Vue.REV : REV (); break;
case Vue.SAR_IMM: SAR_IMM(); break;
case Vue.SAR_REG: SAR_REG(); break;
//case Vue.SCH0BSD: SCH0BSD(); break;
//case Vue.SCH0BSU: SCH0BSU(); break;
//case Vue.SCH1BSD: SCH1BSD(); break;
//case Vue.SCH1BSU: SCH1BSU(); break;
case Vue.SEI : SEI (); break;
case Vue.SETF : SETF (); break;
case Vue.SHL_IMM: SHL_IMM(); break;
case Vue.SHL_REG: SHL_REG(); break;
case Vue.SHR_IMM: SHR_IMM(); break;
case Vue.SHR_REG: SHR_REG(); break;
case Vue.ST_B : ST_B (); break;
case Vue.ST_H : ST_H (); break;
case Vue.ST_W : ST_W (); break;
case Vue.STSR : STSR (); break;
case Vue.SUB : SUB (); break;
case Vue.SUBF_S : SUBF_S (); break;
case Vue.TRAP : TRAP (); break;
case Vue.TRNC_SW: TRNC_SW(); break;
case Vue.XB : XB (); break;
case Vue.XH : XH (); break;
case Vue.XOR : XOR (); break;
//case Vue.XORBSU : XORBSU (); break;
case Vue.XORI : XORI (); break;
//case Vue.XORNBSU: XORNBSU(); break;
default: // Invalid instruction
exception.code = 0xFF90;
}
@ -441,7 +441,7 @@ this.cycles = 0; // DEBUG: Stop processing after execute
private boolean fetch() {
// Read the bits from the bus
if (read(pc + (fetch << 1), VUE.U16, fetch))
if (read(pc + (fetch << 1), Vue.U16, fetch))
return true;
// First unit
@ -534,7 +534,7 @@ this.cycles = 0; // DEBUG: Stop processing after execute
vue.breakCode = vue.onWrite.call(vue, access);
if (vue.breakCode != 0)
return true;
if (access.type == VUE.CANCEL)
if (access.type == Vue.CANCEL)
return false;
}
@ -751,14 +751,14 @@ this.cycles = 0; // DEBUG: Stop processing after execute
int left = program[inst.reg2];
// Retrieve the lock word
if (read(address, VUE.S32, -1))
if (read(address, Vue.S32, -1))
return;
int lock = access.value;
// Compare and exchange
if (lock == left)
access.value = program[30];
if (write(address, VUE.S32, access.value))
if (write(address, Vue.S32, access.value))
return;
// Update CPU state
@ -884,17 +884,17 @@ this.cycles = 0; // DEBUG: Stop processing after execute
// Input Byte from Port
private void IN_B() {
IN_LD(VUE.U8);
IN_LD(Vue.U8);
}
// Input Halfword from Port
private void IN_H() {
IN_LD(VUE.U16);
IN_LD(Vue.U16);
}
// Input Word from Port
private void IN_W() {
IN_LD(VUE.S32);
IN_LD(Vue.S32);
}
// Jump and Link
@ -915,17 +915,17 @@ this.cycles = 0; // DEBUG: Stop processing after execute
// Load Byte
private void LD_B() {
IN_LD(VUE.S8);
IN_LD(Vue.S8);
}
// Load Halfword
private void LD_H() {
IN_LD(VUE.S16);
IN_LD(Vue.S16);
}
// Load Word
private void LD_W() {
IN_LD(VUE.S32);
IN_LD(Vue.S32);
}
// Load to System Register
@ -1005,27 +1005,27 @@ this.cycles = 0; // DEBUG: Stop processing after execute
// Output Byte to Port
private void OUT_B() {
OUT_ST(VUE.U8);
OUT_ST(Vue.U8);
}
// Output Halfword to Port
private void OUT_H() {
OUT_ST(VUE.U16);
OUT_ST(Vue.U16);
}
// Output Word to Port
private void OUT_W() {
OUT_ST(VUE.S32);
OUT_ST(Vue.S32);
}
// Return from Trap or Interrupt
private void RETI() {
if (psw_np == 1) {
pc = fepc;
setSystemRegister(VUE.PSW, fepsw, false);
setSystemRegister(Vue.PSW, fepsw, false);
} else {
pc = eipc;
setSystemRegister(VUE.PSW, eipsw, false);
setSystemRegister(Vue.PSW, eipsw, false);
}
}
@ -1082,17 +1082,17 @@ this.cycles = 0; // DEBUG: Stop processing after execute
// Store Byte
private void ST_B() {
OUT_ST(VUE.S8);
OUT_ST(Vue.S8);
}
// Store Halfword
private void ST_H() {
OUT_ST(VUE.S16);
OUT_ST(Vue.S16);
}
// Store Word
private void ST_W() {
OUT_ST(VUE.S32);
OUT_ST(Vue.S32);
}
// Store Contents of System Register

View File

@ -10,7 +10,7 @@ class GamePak {
int wcr_rom1w; // ROM one-wait mode
// Private fields
private JavaVUE vue; // Emulation state
private JavaVue vue; // Emulation state
@ -19,7 +19,7 @@ class GamePak {
///////////////////////////////////////////////////////////////////////////
// Default constructor
GamePak(JavaVUE vue) {
GamePak(JavaVue vue) {
this.vue = vue;
}

View File

@ -28,38 +28,38 @@ public class Instruction {
// Opcode lookup table
private static final byte[] LOOKUP_OPCODE = {
VUE.MOV_REG, 1, VUE.ADD_REG, 1, VUE.SUB , 1, VUE.CMP_REG, 1,
VUE.SHL_REG, 1, VUE.SHR_REG, 1, VUE.JMP , 1, VUE.SAR_REG, 1,
VUE.MUL , 1, VUE.DIV , 1, VUE.MULU , 1, VUE.DIVU , 1,
VUE.OR , 1, VUE.AND , 1, VUE.XOR , 1, VUE.NOT , 1,
VUE.MOV_IMM,-2, VUE.ADD_IMM,-2, VUE.SETF , 2, VUE.CMP_IMM,-2,
VUE.SHL_IMM, 2, VUE.SHR_IMM, 2, VUE.CLI , 2, VUE.SAR_IMM, 2,
VUE.TRAP , 2, VUE.RETI , 2, VUE.HALT , 2, VUE.ILLEGAL, 0,
VUE.LDSR , 2, VUE.STSR , 2, VUE.SEI , 2, BITSTRING , 2,
VUE.BCOND , 3, VUE.BCOND , 3, VUE.BCOND , 3, VUE.BCOND , 3,
VUE.BCOND , 3, VUE.BCOND , 3, VUE.BCOND , 3, VUE.BCOND , 3,
VUE.MOVEA ,-5, VUE.ADDI ,-5, VUE.JR , 4, VUE.JAL , 4,
VUE.ORI , 5, VUE.ANDI , 5, VUE.XORI , 5, VUE.MOVHI , 5,
VUE.LD_B , 6, VUE.LD_H , 6, VUE.ILLEGAL, 0, VUE.LD_W , 6,
VUE.ST_B , 6, VUE.ST_H , 6, VUE.ILLEGAL, 0, VUE.ST_W , 6,
VUE.IN_B , 6, VUE.IN_H , 6, VUE.CAXI , 6, VUE.IN_W , 6,
VUE.OUT_B , 6, VUE.OUT_H , 6, FLOATENDO , 7, VUE.OUT_W , 6
Vue.MOV_REG, 1, Vue.ADD_REG, 1, Vue.SUB , 1, Vue.CMP_REG, 1,
Vue.SHL_REG, 1, Vue.SHR_REG, 1, Vue.JMP , 1, Vue.SAR_REG, 1,
Vue.MUL , 1, Vue.DIV , 1, Vue.MULU , 1, Vue.DIVU , 1,
Vue.OR , 1, Vue.AND , 1, Vue.XOR , 1, Vue.NOT , 1,
Vue.MOV_IMM,-2, Vue.ADD_IMM,-2, Vue.SETF , 2, Vue.CMP_IMM,-2,
Vue.SHL_IMM, 2, Vue.SHR_IMM, 2, Vue.CLI , 2, Vue.SAR_IMM, 2,
Vue.TRAP , 2, Vue.RETI , 2, Vue.HALT , 2, Vue.ILLEGAL, 0,
Vue.LDSR , 2, Vue.STSR , 2, Vue.SEI , 2, BITSTRING , 2,
Vue.BCOND , 3, Vue.BCOND , 3, Vue.BCOND , 3, Vue.BCOND , 3,
Vue.BCOND , 3, Vue.BCOND , 3, Vue.BCOND , 3, Vue.BCOND , 3,
Vue.MOVEA ,-5, Vue.ADDI ,-5, Vue.JR , 4, Vue.JAL , 4,
Vue.ORI , 5, Vue.ANDI , 5, Vue.XORI , 5, Vue.MOVHI , 5,
Vue.LD_B , 6, Vue.LD_H , 6, Vue.ILLEGAL, 0, Vue.LD_W , 6,
Vue.ST_B , 6, Vue.ST_H , 6, Vue.ILLEGAL, 0, Vue.ST_W , 6,
Vue.IN_B , 6, Vue.IN_H , 6, Vue.CAXI , 6, Vue.IN_W , 6,
Vue.OUT_B , 6, Vue.OUT_H , 6, FLOATENDO , 7, Vue.OUT_W , 6
};
// Bit string lookup table
private static final byte[] LOOKUP_BITSTRING = {
VUE.SCH0BSU, VUE.SCH0BSD, VUE.SCH1BSU, VUE.SCH1BSD,
VUE.ILLEGAL, VUE.ILLEGAL, VUE.ILLEGAL, VUE.ILLEGAL,
VUE.ORBSU , VUE.ANDBSU , VUE.XORBSU , VUE.MOVBSU ,
VUE.ORNBSU , VUE.ANDNBSU, VUE.XORNBSU, VUE.XORNBSU
Vue.SCH0BSU, Vue.SCH0BSD, Vue.SCH1BSU, Vue.SCH1BSD,
Vue.ILLEGAL, Vue.ILLEGAL, Vue.ILLEGAL, Vue.ILLEGAL,
Vue.ORBSU , Vue.ANDBSU , Vue.XORBSU , Vue.MOVBSU ,
Vue.ORNBSU , Vue.ANDNBSU, Vue.XORNBSU, Vue.XORNBSU
};
// Floating-point and Nintendo lookup table
private static final byte[] LOOKUP_FLOATENDO = {
VUE.CMPF_S , VUE.ILLEGAL, VUE.CVT_WS , VUE.CVT_SW ,
VUE.ADDF_S , VUE.SUBF_S , VUE.MULF_S , VUE.DIVF_S ,
VUE.XB , VUE.XH , VUE.REV , VUE.TRNC_SW,
VUE.MPYHW , VUE.ILLEGAL, VUE.ILLEGAL, VUE.ILLEGAL
Vue.CMPF_S , Vue.ILLEGAL, Vue.CVT_WS , Vue.CVT_SW ,
Vue.ADDF_S , Vue.SUBF_S , Vue.MULF_S , Vue.DIVF_S ,
Vue.XB , Vue.XH , Vue.REV , Vue.TRNC_SW,
Vue.MPYHW , Vue.ILLEGAL, Vue.ILLEGAL, Vue.ILLEGAL
};
@ -120,7 +120,7 @@ public class Instruction {
reg2 = bits >> 21 & 31;
imm = extend < 0 ? bits << 11 >> 27 : bits >> 16 & 31;
if (id == BITSTRING)
id = imm >= 16 ? VUE.ILLEGAL : LOOKUP_BITSTRING[imm];
id = imm >= 16 ? Vue.ILLEGAL : LOOKUP_BITSTRING[imm];
break;
case 3:
opcode = 0x20;
@ -144,7 +144,7 @@ public class Instruction {
reg2 = bits >> 21 & 31;
reg1 = bits >> 16 & 31;
subopcode = bits >> 10 & 63;
id = subopcode >= 16 ? VUE.ILLEGAL :
id = subopcode >= 16 ? Vue.ILLEGAL :
LOOKUP_FLOATENDO[subopcode];
break;
}

View File

@ -4,7 +4,7 @@ package vue;
import java.util.*;
// Java emulation core implementation
class JavaVUE extends VUE {
class JavaVue extends Vue {
// Package fields
int breakCode; // Application break code
@ -32,7 +32,7 @@ class JavaVUE extends VUE {
///////////////////////////////////////////////////////////////////////////
// Default constructor
JavaVUE() {
JavaVue() {
cpu = new CPU (this);
pak = new GamePak(this);
wram = new byte[0x10000];
@ -107,11 +107,11 @@ class JavaVUE extends VUE {
// Non-indexed registers
if (system) switch (index) {
case VUE.JUMP_FROM: return
case Vue.JUMP_FROM: return
cpu.jumpFrom[cpu.psw_np != 0 ? 2 : cpu.psw_ep];
case VUE.JUMP_TO : return
case Vue.JUMP_TO : return
cpu.jumpTo [cpu.psw_np != 0 ? 2 : cpu.psw_ep];
case VUE.PC : return cpu.pc;
case Vue.PC : return cpu.pc;
}
// Indexed registers
@ -202,7 +202,7 @@ class JavaVUE extends VUE {
// Specify a register value
public int setRegister(int index, boolean system, int value) {
return
index == VUE.PC && system ? cpu.pc = value & 0xFFFFFFFE :
index == Vue.PC && system ? cpu.pc = value & 0xFFFFFFFE :
index < 0 || index > 31 ? 0 :
system ? cpu.setSystemRegister(index, value, true) :
index == 0 ? 0 : (cpu.program[index] = value)
@ -285,16 +285,16 @@ class JavaVUE extends VUE {
int value = 0;
address &= ~size + 1 & data.length - 1;
switch (type) {
case VUE.S32: value =
case Vue.S32: value =
data[address + 3] << 24 |
(data[address + 2] & 0xFF) << 16;
// Fallthrough
case VUE.S16: // Fallthrough
case VUE.U16: value |=
case Vue.S16: // Fallthrough
case Vue.U16: value |=
(data[address + 1] & 0xFF) << 8;
// Fallthrough
case VUE.S8 : // Fallthrough
case VUE.U8 : value |=
case Vue.S8 : // Fallthrough
case Vue.U8 : value |=
data[address ] & 0xFF;
}
@ -340,16 +340,16 @@ class JavaVUE extends VUE {
int size = TYPE_SIZES[type];
address &= ~size + 1 & data.length - 1;
switch (type) {
case VUE.S32:
case Vue.S32:
data[address + 3] = (byte) (value >> 24);
data[address + 2] = (byte) (value >> 16);
// Fallthrough
case VUE.S16: // Fallthrough
case VUE.U16:
case Vue.S16: // Fallthrough
case Vue.U16:
data[address + 1] = (byte) (value >> 8);
// Fallthrough
case VUE.S8 : // Fallthrough
case VUE.U8 : value |=
case Vue.S8 : // Fallthrough
case Vue.U8 : value |=
data[address ] = (byte) value;
}

View File

@ -1,91 +0,0 @@
package vue;
// Native-backed emulation core implementation
class NativeVUE extends VUE {
// Instance fields
private byte[] pointer; // Context address in native memory
///////////////////////////////////////////////////////////////////////////
// Constructors //
///////////////////////////////////////////////////////////////////////////
// Default constructor
NativeVUE() {
pointer = construct();
}
///////////////////////////////////////////////////////////////////////////
// Public Methods //
///////////////////////////////////////////////////////////////////////////
// Release any used resources
public native void dispose();
// Process the simulation
public native int emulate(int maxCycles);
// Evaluate the condition in a breakpoint
public native boolean evaluate(Breakpoint brk);
// Retrieve the application break code
public native int getBreakCode();
// Retrieve a register value
public native int getRegister(int index, boolean system);
// Retrieve a copy of the ROM data
public native byte[] getROM();
// Determine whether the context is native-backed
public native boolean isNative();
// Read a value from the CPU bus
public native int read(int address, int type);
// Read bytes from the CPU bus
public native boolean readBytes(int address, byte[] dest, int offset,
int length);
// Initialize all system components
public native void reset();
// Specify an exception breakpoint callback
public native void setException(OnException callback);
// Specify an execute breakpoint callback
public native void setExecute(OnExecute callback);
// Specify a read breakpoint callback
public native void setRead(OnRead callback);
// Specify a register value
public native int setRegister(int index, boolean system, int value);
// Provide new ROM data
public native boolean setROM(byte[] data, int offset, int length);
// Specify a write breakpoint callback
public native void setWrite(OnWrite callback);
// Write a value to the CPU bus
public native void write(int address, int type, int value);
// Write bytes to the CPU bus
public native boolean writeBytes(int address, byte[] src, int offset,
int length);
///////////////////////////////////////////////////////////////////////////
// Private Methods //
///////////////////////////////////////////////////////////////////////////
// Native constructor
private native byte[] construct();
}

View File

@ -5,7 +5,7 @@
#include <math.h>
#include <jni.h>
#include <vue.h>
#include "vue_NativeVUE.h"
#include "vue_NativeVue.h"
@ -26,7 +26,7 @@ static const int TYPE_SIZES[] = { 1, 1, 2, 2, 4 };
typedef struct {
int32_t type;
int32_t value;
} TOKEN;
} Token;
// Precompiled breakpoint
typedef struct {
@ -34,16 +34,16 @@ typedef struct {
int32_t numAddresses; // Number of address ranges
int32_t numCondition; // Number of tokens in condition
int32_t *addresses; // Address ranges
TOKEN *condition; // Condition tokens in RPN order
} BREAKPOINT;
Token *condition; // Condition tokens in RPN order
} Breakpoint;
// Core context state type
typedef struct {
VUE vue; // Context into the generic C library
Vue vue; // Context into the generic C library
int32_t numBreakpoints; // Number of breakpoints
BREAKPOINT *breakpoints; // Application breakpoints
Breakpoint *breakpoints; // Application breakpoints
int32_t *stack; // Expression stack for breakpoints
} CORE;
} Core;
@ -61,7 +61,7 @@ typedef struct {
// Component Includes //
///////////////////////////////////////////////////////////////////////////////
#define NATIVEVUE
#define NATIVEVue
#include "Breakpoint.c"
@ -70,15 +70,6 @@ typedef struct {
// Internal Functions //
///////////////////////////////////////////////////////////////////////////////
// Retrieve the handle to a NativeVUE's core context
static CORE* GetCore(JNIEnv *env, jobject vue) {
jbyteArray pointer = (*env)->GetObjectField(env, vue, (*env)->GetFieldID(
env, (*env)->GetObjectClass(env, vue), "pointer", "[B"));
jbyte *elems = (*env)->GetByteArrayElements(env, pointer, NULL);
CORE *core = *(CORE **)elems;
(*env)->ReleaseByteArrayElements(env, pointer, elems, 0);
return core;
}
@ -87,26 +78,19 @@ static CORE* GetCore(JNIEnv *env, jobject vue) {
///////////////////////////////////////////////////////////////////////////////
// Native constructor
JNIEXPORT jbyteArray JNICALL Java_vue_NativeVUE_construct
JNIEXPORT jlong JNICALL Java_vue_NativeVue_construct
(JNIEnv *env, jobject vue) {
// Produce and initialize a new core context
CORE *core = calloc(sizeof (CORE), 1);
Core *mem[] = { NULL, NULL };
Core *core = mem[0] = calloc(sizeof (Core), 1);
vueInitialize(&core->vue);
vueReset(&core->vue);
// Encode the context handle into a byte array
jbyteArray pointer = (*env)->NewByteArray(env, sizeof (void *));
jbyte *elems = (*env)->GetByteArrayElements(env, pointer, NULL);
*(CORE **)elems = core;
(*env)->ReleaseByteArrayElements(env, pointer, elems, 0);
return pointer;
return *(jlong *)&core;
}
// Release any used resources
JNIEXPORT void JNICALL Java_vue_NativeVUE_dispose
(JNIEnv *env, jobject vue) {
CORE *core = GetCore(env, vue);
JNIEXPORT void JNICALL Java_vue_NativeVue_dispose
(JNIEnv *env, jobject vue, jlong handle) {
Core *core = *(Core **)&handle;
if (core->vue.pak.rom != NULL)
free(core->vue.pak.rom);
if (core->vue.pak.ram != NULL)
@ -115,30 +99,37 @@ JNIEXPORT void JNICALL Java_vue_NativeVUE_dispose
}
// Process the simulation
JNIEXPORT jint JNICALL Java_vue_NativeVUE_emulate
(JNIEnv *env, jobject vue, jint maxCycles) {
CORE *core = GetCore(env, vue);
JNIEXPORT jint JNICALL Java_vue_NativeVue_emulate
(JNIEnv *env, jobject vue, jlong handle, jint maxCycles) {
Core *core = *(Core **)&handle;
return vueEmulate(&core->vue, maxCycles);
}
// Evaluate the condition in a breakpoint
JNIEXPORT jboolean JNICALL Java_vue_NativeVue_evaluate
(JNIEnv *env, jobject vue, jlong handle, jobject brk) {
Core *core = *(Core **)&handle;
return JNI_FALSE;
}
// Retrieve the application break code
JNIEXPORT jint JNICALL Java_vue_NativeVUE_getBreakCode
(JNIEnv *env, jobject vue) {
CORE *core = GetCore(env, vue);
JNIEXPORT jint JNICALL Java_vue_NativeVue_getBreakCode
(JNIEnv *env, jobject vue, jlong handle) {
Core *core = *(Core **)&handle;
return vueGetBreakCode(&core->vue);
}
// Retrieve a register value
JNIEXPORT jint JNICALL Java_vue_NativeVUE_getRegister
(JNIEnv *env, jobject vue, jint index, jboolean system) {
CORE *core = GetCore(env, vue);
JNIEXPORT jint JNICALL Java_vue_NativeVue_getRegister
(JNIEnv *env, jobject vue, jlong handle, jint index, jboolean system) {
Core *core = *(Core **)&handle;
return vueGetRegister(&core->vue, index, system);;
}
// Retrieve a copy of the ROM data
JNIEXPORT jbyteArray JNICALL Java_vue_NativeVUE_getROM
(JNIEnv *env, jobject vue) {
CORE *core = GetCore(env, vue);
JNIEXPORT jbyteArray JNICALL Java_vue_NativeVue_getROM
(JNIEnv *env, jobject vue, jlong handle) {
Core *core = *(Core **)&handle;
// No ROM data
if (core->vue.pak.rom == NULL)
@ -153,22 +144,22 @@ JNIEXPORT jbyteArray JNICALL Java_vue_NativeVUE_getROM
}
// Determine whether the context is native-backed
JNIEXPORT jboolean JNICALL Java_vue_NativeVUE_isNative
JNIEXPORT jboolean JNICALL Java_vue_NativeVue_isNative
(JNIEnv *env, jobject vue) {
return JNI_TRUE;
}
// Read a value from the CPU bus
JNIEXPORT jint JNICALL Java_vue_NativeVUE_read
(JNIEnv *env, jobject vue, jint address, jint type) {
CORE *core = GetCore(env, vue);
JNIEXPORT jint JNICALL Java_vue_NativeVue_read
(JNIEnv *env, jobject vue, jlong handle, jint address, jint type) {
Core *core = *(Core **)&handle;
return vueRead(&core->vue, address, type);
}
// Read bytes from the CPU bus
JNIEXPORT jboolean JNICALL Java_vue_NativeVUE_readBytes
(JNIEnv *env, jobject vue, jint address, jbyteArray data, jint offset,
jint length) {
JNIEXPORT jboolean JNICALL Java_vue_NativeVue_readBytes
(JNIEnv *env, jobject vue, jlong handle, jint address, jbyteArray data,
jint offset, jint length) {
// Error checking
if (
@ -179,7 +170,7 @@ JNIEXPORT jboolean JNICALL Java_vue_NativeVUE_readBytes
) return JNI_FALSE;
// Perform the operation
CORE *core = GetCore(env, vue);
Core *core = *(Core **)&handle;
jbyte *elems = (*env)->GetByteArrayElements(env, data, NULL);
vueReadBytes(&core->vue, address, &elems[offset], length);
(*env)->ReleaseByteArrayElements(env, data, elems, 0);
@ -187,40 +178,42 @@ JNIEXPORT jboolean JNICALL Java_vue_NativeVUE_readBytes
}
// Initialize all system components
JNIEXPORT void JNICALL Java_vue_NativeVUE_reset
(JNIEnv *env, jobject vue) {
CORE *core = GetCore(env, vue);
JNIEXPORT void JNICALL Java_vue_NativeVue_reset
(JNIEnv *env, jobject vue, jlong handle) {
Core *core = *(Core **)&handle;
vueReset(&core->vue);
}
// Specify an exception breakpoint callback
JNIEXPORT void JNICALL Java_vue_NativeVUE_setException
(JNIEnv *env, jobject vue, jobject onException) {
CORE *core = GetCore(env, vue);
JNIEXPORT void JNICALL Java_vue_NativeVue_setException
(JNIEnv *env, jobject vue, jlong handle, jobject onException) {
Core *core = *(Core **)&handle;
}
// Specify an execute breakpoint callback
JNIEXPORT void JNICALL Java_vue_NativeVUE_setExecute
(JNIEnv *env, jobject vue, jobject onExecute) {
CORE *core = GetCore(env, vue);
JNIEXPORT void JNICALL Java_vue_NativeVue_setExecute
(JNIEnv *env, jobject vue, jlong handle, jobject onExecute) {
Core *core = *(Core **)&handle;
}
// Specify a read breakpoint callback
JNIEXPORT void JNICALL Java_vue_NativeVUE_setRead
(JNIEnv *env, jobject vue, jobject onRead) {
CORE *core = GetCore(env, vue);
JNIEXPORT void JNICALL Java_vue_NativeVue_setRead
(JNIEnv *env, jobject vue, jlong handle, jobject onRead) {
Core *core = *(Core **)&handle;
}
// Specify a register value
JNIEXPORT jint JNICALL Java_vue_NativeVUE_setRegister
(JNIEnv *env, jobject vue, jint index, jboolean system, jint value) {
CORE *core = GetCore(env, vue);
JNIEXPORT jint JNICALL Java_vue_NativeVue_setRegister
(JNIEnv *env, jobject vue, jlong handle, jint index, jboolean system,
jint value) {
Core *core = *(Core **)&handle;
return vueSetRegister(&core->vue, index, system, value);
}
// Provide new ROM data
JNIEXPORT jboolean JNICALL Java_vue_NativeVUE_setROM
(JNIEnv *env, jobject vue, jbyteArray data, jint offset, jint length) {
JNIEXPORT jboolean JNICALL Java_vue_NativeVue_setROM
(JNIEnv *env, jobject vue, jlong handle, jbyteArray data, jint offset,
jint length) {
// Error checking
if (
@ -238,7 +231,7 @@ JNIEXPORT jboolean JNICALL Java_vue_NativeVUE_setROM
(*env)->ReleaseByteArrayElements(env, data, elems, 0);
// Transfer the ROM data to the emulation state
CORE *core = GetCore(env, vue);
Core *core = *(Core **)&handle;
if (core->vue.pak.rom != NULL)
free(core->vue.pak.rom);
vueSetROM(&core->vue, rom, length);
@ -246,22 +239,23 @@ JNIEXPORT jboolean JNICALL Java_vue_NativeVUE_setROM
}
// Specify a write breakpoint callback
JNIEXPORT void JNICALL Java_vue_NativeVUE_setWrite
(JNIEnv *env, jobject vue, jobject onWrite) {
CORE *core = GetCore(env, vue);
JNIEXPORT void JNICALL Java_vue_NativeVue_setWrite
(JNIEnv *env, jobject vue, jlong handle, jobject onWrite) {
Core *core = *(Core **)&handle;
}
// Write a value to the CPU bus
JNIEXPORT void JNICALL Java_vue_NativeVUE_write
(JNIEnv *env, jobject vue, jint address, jint type, jint value) {
CORE *core = GetCore(env, vue);
JNIEXPORT void JNICALL Java_vue_NativeVue_write
(JNIEnv *env, jobject vue, jlong handle, jint address, jint type,
jint value) {
Core *core = *(Core **)&handle;
vueWrite(&core->vue, address, type, value);
}
// Write bytes to the CPU bus
JNIEXPORT jboolean JNICALL Java_vue_NativeVUE_writeBytes
(JNIEnv *env, jobject vue, jint address, jbyteArray data, jint offset,
jint length) {
JNIEXPORT jboolean JNICALL Java_vue_NativeVue_writeBytes
(JNIEnv *env, jobject vue, jlong handle, jint address, jbyteArray data,
jint offset, jint length) {
// Error checking
if (
@ -272,7 +266,7 @@ JNIEXPORT jboolean JNICALL Java_vue_NativeVUE_writeBytes
) return JNI_FALSE;
// Perform the operation
CORE *core = GetCore(env, vue);
Core *core = *(Core **)&handle;
jbyte *elems = (*env)->GetByteArrayElements(env, data, NULL);
vueWriteBytes(&core->vue, address, &elems[offset], length);
(*env)->ReleaseByteArrayElements(env, data, elems, 0);

View File

@ -0,0 +1,117 @@
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 //
///////////////////////////////////////////////////////////////////////////
// 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); }
// Evaluate the condition in a breakpoint
private native boolean evaluate(long handle, Breakpoint brk);
public boolean evaluate(Breakpoint brk)
{ return evaluate(handle, brk); }
// Retrieve the application break code
private native int getBreakCode(long handle);
public int getBreakCode() { return getBreakCode(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 native boolean isNative();
// 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); }
// Initialize all system components
private native void reset(long handle);
public void reset()
{ reset(handle); }
// Specify an exception breakpoint callback
private native void setException(long handle, OnException callback);
public void setException(OnException callback)
{ setException(handle, callback); }
// Specify an execute breakpoint callback
private native void setExecute(long handle, OnExecute callback);
public void setExecute(OnExecute callback)
{ setExecute(handle, callback); }
// Specify a read breakpoint callback
private native void setRead(long handle, OnRead callback);
public void setRead(OnRead callback)
{ setRead(handle, callback); }
// 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); }
// Specify a write breakpoint callback
private native void setWrite(long handle, OnWrite callback);
public void setWrite(OnWrite callback)
{ setWrite(handle, callback); }
// 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); }
}

View File

@ -1,7 +1,7 @@
package vue;
// Template for emulation core implementations
public abstract class VUE {
public abstract class Vue {
// Static fields
private static String nativeID = null; // ID of loaded native library
@ -12,10 +12,10 @@ public abstract class VUE {
// Types //
///////////////////////////////////////////////////////////////////////////
public interface OnException { int call(VUE vue, Ecxeption exp ); }
public interface OnExecute { int call(VUE vue, Instruction inst ); }
public interface OnRead { int call(VUE vue, Access access); }
public interface OnWrite { int call(VUE vue, Access access); }
public interface OnException { int call(Vue vue, Ecxeption exp ); }
public interface OnExecute { int call(Vue vue, Instruction inst ); }
public interface OnRead { int call(Vue vue, Access access); }
public interface OnWrite { int call(Vue vue, Access access); }
@ -141,9 +141,9 @@ public abstract class VUE {
///////////////////////////////////////////////////////////////////////////
// Produce an emulation core context
public static VUE create(boolean useNative) {
return !useNative ? new JavaVUE() :
isNativeLoaded() ? new NativeVUE() : null;
public static Vue create(boolean useNative) {
return !useNative ? new JavaVue() :
isNativeLoaded() ? new NativeVue() : null;
}
// Retrieve the ID of the loaded native library, if any
@ -158,7 +158,7 @@ public abstract class VUE {
// Specify the ID of the loaded native library
public static void setNativeID(String nativeID) {
VUE.nativeID = nativeID;
Vue.nativeID = nativeID;
}
@ -167,6 +167,12 @@ public abstract class VUE {
// Public Methods //
///////////////////////////////////////////////////////////////////////////
// Attach a breakpoint
//public abstract boolean attachBreakpoint(Breakpoint brk);
// Detach a breakpoint
//public abstract boolean detachBreakpoint(Breakpoint brk);
// Release any used resources
public abstract void dispose();
@ -198,24 +204,12 @@ public abstract class VUE {
// Initialize all system components
public abstract void reset();
// Specify an exception breakpoint callback
public abstract void setException(OnException callback);
// Specify an execute breakpoint callback
public abstract void setExecute(OnExecute callback);
// Specify a read breakpoint callback
public abstract void setRead(OnRead callback);
// Specify a register value
public abstract int setRegister(int index, boolean system, int value);
// Provide new ROM data
public abstract boolean setROM(byte[] data, int offset, int length);
// Specify a write breakpoint callback
public abstract void setWrite(OnWrite callback);
// Write a value to the CPU bus
public abstract void write(int address, int type, int value);