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

View File

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

View File

@ -141,7 +141,7 @@ extern "C" {
*****************************************************************************/ *****************************************************************************/
/* Forward references */ /* Forward references */
typedef struct VUE VUE; typedef struct Vue Vue;
/* Boolean */ /* Boolean */
typedef int vbool; typedef int vbool;
@ -152,12 +152,12 @@ typedef struct {
int32_t value; /* Value read/to write */ int32_t value; /* Value read/to write */
int8_t fetch; /* Index of machine code unit */ int8_t fetch; /* Index of machine code unit */
int8_t type; /* Data type */ int8_t type; /* Data type */
} VUE_ACCESS; } VueAccess;
/* Exception state */ /* Exception state */
typedef struct { typedef struct {
uint16_t code; /* Exception code */ uint16_t code; /* Exception code */
} VUE_EXCEPTION; } VueException;
/* Instruction state */ /* Instruction state */
typedef struct { typedef struct {
@ -172,36 +172,36 @@ typedef struct {
uint8_t reg2; /* Destination/left register */ uint8_t reg2; /* Destination/left register */
uint8_t size; /* Number of bytes in encoding */ uint8_t size; /* Number of bytes in encoding */
uint8_t subopcode; /* Instruction subopcode */ uint8_t subopcode; /* Instruction subopcode */
} VUE_INSTRUCTION; } VueInstruction;
/* Callbacks */ /* Callbacks */
typedef int32_t (*VUE_ONEXCEPTION)(VUE *, VUE_EXCEPTION *); typedef int32_t (*VueOnException)(Vue *, VueException *);
typedef int32_t (*VUE_ONEXECUTE )(VUE *, VUE_INSTRUCTION *); typedef int32_t (*VueOnExecute )(Vue *, VueInstruction *);
typedef int32_t (*VUE_ONREAD )(VUE *, VUE_ACCESS *); typedef int32_t (*VueOnRead )(Vue *, VueAccess *);
typedef int32_t (*VUE_ONWRITE )(VUE *, VUE_ACCESS *); typedef int32_t (*VueOnWrite )(Vue *, VueAccess *);
/* Emulation state */ /* Emulation state */
struct VUE { struct Vue {
int32_t breakCode; /* Application break code */ int32_t breakCode; /* Application break code */
uint8_t wram[0x10000]; /* System memory */ uint8_t wram[0x10000]; /* System memory */
/* Callback handlers */ /* Callback handlers */
VUE_ONEXCEPTION onException; VueOnException onException;
VUE_ONEXECUTE onExecute; VueOnExecute onExecute;
VUE_ONREAD onRead; VueOnRead onRead;
VUE_ONWRITE onWrite; VueOnWrite onWrite;
/* CPU state */ /* CPU state */
struct { struct {
VUE_ACCESS access; /* Access state */ VueAccess access; /* Access state */
VUE_EXCEPTION exception; /* Exception state */ VueException exception; /* Exception state */
VUE_INSTRUCTION inst; /* Instruction state */ VueInstruction inst; /* Instruction state */
int32_t cycles; /* Cycles until next stage */ int32_t cycles; /* Cycles until next stage */
int32_t jumpFrom[3]; /* Source PCs of most recent jumps */ int32_t jumpFrom[3]; /* Source PCs of most recent jumps */
int32_t jumpTo [3]; /* Destination PCs of most recent jumps */ int32_t jumpTo [3]; /* Destination PCs of most recent jumps */
uint16_t irq; /* Interrupt lines */ uint16_t irq; /* Interrupt lines */
int fetch; /* Fetch unit index */ int fetch; /* Fetch unit index */
int stage; /* Current processing stage */ int stage; /* Current processing stage */
/* Program registers */ /* Program registers */
int32_t program[32]; int32_t program[32];
@ -265,21 +265,21 @@ struct VUE {
* Function Prototypes * * Function Prototypes *
*****************************************************************************/ *****************************************************************************/
VUEAPI int32_t vueEmulate (VUE *vue, int32_t maxCycles); VUEAPI int32_t vueEmulate (Vue *vue, int32_t maxCycles);
VUEAPI int32_t vueGetBreakCode(VUE *vue); VUEAPI int32_t vueGetBreakCode(Vue *vue);
VUEAPI int32_t vueGetRegister (VUE *vue, int32_t index, vbool system); VUEAPI int32_t vueGetRegister (Vue *vue, int32_t index, vbool system);
VUEAPI void vueInitialize (VUE *vue); VUEAPI void vueInitialize (Vue *vue);
VUEAPI int32_t vueRead (VUE *vue, uint32_t address, int32_t type); 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 vbool vueReadBytes (Vue *vue, uint32_t address, uint8_t *dest, uint32_t length);
VUEAPI void vueReset (VUE *vue); VUEAPI void vueReset (Vue *vue);
VUEAPI void vueSetException(VUE *vue, VUE_ONEXCEPTION callback); VUEAPI void vueSetException(Vue *vue, VueOnException callback);
VUEAPI void vueSetExecute (VUE *vue, VUE_ONEXECUTE callback); VUEAPI void vueSetExecute (Vue *vue, VueOnExecute callback);
VUEAPI void vueSetRead (VUE *vue, VUE_ONREAD callback); VUEAPI void vueSetRead (Vue *vue, VueOnRead callback);
VUEAPI int32_t vueSetRegister (VUE *vue, int32_t index, vbool system, int32_t value); 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 vbool vueSetROM (Vue *vue, uint8_t *rom, uint32_t size);
VUEAPI void vueSetWrite (VUE *vue, VUE_ONWRITE callback); VUEAPI void vueSetWrite (Vue *vue, VueOnWrite callback);
VUEAPI void vueWrite (VUE *vue, uint32_t address, int32_t type, int32_t value); 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 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 */ /* 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 */ int32_t cycles; /* Number of cycles to process */
/* Process up to the given number of cycles */ /* 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 */ /* Retrieve the application break code */
int32_t vueGetBreakCode(VUE *vue) { int32_t vueGetBreakCode(Vue *vue) {
return vue == NULL ? 0 : vue->breakCode; return vue == NULL ? 0 : vue->breakCode;
} }
/* Retrieve the value of a register */ /* 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 */ /* Error checking */
if (vue == NULL) if (vue == NULL)
@ -229,7 +229,7 @@ int32_t vueGetRegister(VUE *vue, int32_t index, vbool system) {
} }
/* Prepare an emulation state context for use */ /* Prepare an emulation state context for use */
void vueInitialize(VUE *vue) { void vueInitialize(Vue *vue) {
if (vue == NULL) if (vue == NULL)
return; return;
vue->onException = NULL; vue->onException = NULL;
@ -241,7 +241,7 @@ void vueInitialize(VUE *vue) {
} }
/* Read a value from the CPU bus */ /* 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 */ /* Error checking */
if (vue == NULL) if (vue == NULL)
@ -257,7 +257,7 @@ int32_t vueRead(VUE *vue, uint32_t address, int32_t type) {
} }
/* Read bytes from the CPU bus */ /* 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 */ uint32_t count; /* Bytes to read in one iteration */
/* Error checking */ /* Error checking */
@ -289,7 +289,7 @@ vbool vueReadBytes(VUE *vue, uint32_t address, uint8_t *dest, uint32_t length){
} }
/* Initialize all system components */ /* Initialize all system components */
void vueReset(VUE *vue) { void vueReset(Vue *vue) {
uint32_t x; /* Iterator */ uint32_t x; /* Iterator */
/* Error checking */ /* Error checking */
@ -304,25 +304,25 @@ void vueReset(VUE *vue) {
} }
/* Specify an exception breakpoint callback */ /* Specify an exception breakpoint callback */
void vueSetException(VUE *vue, VUE_ONEXCEPTION callback) { void vueSetException(Vue *vue, VueOnException callback) {
if (vue != NULL) if (vue != NULL)
vue->onException = callback; vue->onException = callback;
} }
/* Specify an execute breakpoint callback */ /* Specify an execute breakpoint callback */
void vueSetExecute(VUE *vue, VUE_ONEXECUTE callback) { void vueSetExecute(Vue *vue, VueOnExecute callback) {
if (vue != NULL) if (vue != NULL)
vue->onExecute = callback; vue->onExecute = callback;
} }
/* Specify a read breakpoint callback */ /* Specify a read breakpoint callback */
void vueSetRead(VUE *vue, VUE_ONREAD callback) { void vueSetRead(Vue *vue, VueOnRead callback) {
if (vue != NULL) if (vue != NULL)
vue->onRead = callback; vue->onRead = callback;
} }
/* Specify a value for a register */ /* 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 : return vue == NULL ? 0 :
index == VUE_PC && system ? vue->cpu.pc = value & 0xFFFFFFFE : index == VUE_PC && system ? vue->cpu.pc = value & 0xFFFFFFFE :
index < 0 || index > 31 ? 0 : 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 */ /* 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 */ /* Error checking */
if ( if (
@ -349,13 +349,13 @@ vbool vueSetROM(VUE *vue, uint8_t *rom, uint32_t size) {
} }
/* Specify a write breakpoint callback */ /* Specify a write breakpoint callback */
void vueSetWrite(VUE *vue, VUE_ONREAD callback) { void vueSetWrite(Vue *vue, VueOnRead callback) {
if (vue != NULL) if (vue != NULL)
vue->onWrite = callback; vue->onWrite = callback;
} }
/* Write a value to the CPU bus */ /* 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 */ /* Error checking */
if (vue == NULL) 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 */ /* 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 */ uint32_t count; /* Bytes to write in one iteration */
/* Error checking */ /* Error checking */

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,7 +4,7 @@ package vue;
import java.util.*; import java.util.*;
// Java emulation core implementation // Java emulation core implementation
class JavaVUE extends VUE { class JavaVue extends Vue {
// Package fields // Package fields
int breakCode; // Application break code int breakCode; // Application break code
@ -32,7 +32,7 @@ class JavaVUE extends VUE {
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Default constructor // Default constructor
JavaVUE() { JavaVue() {
cpu = new CPU (this); cpu = new CPU (this);
pak = new GamePak(this); pak = new GamePak(this);
wram = new byte[0x10000]; wram = new byte[0x10000];
@ -107,11 +107,11 @@ class JavaVUE extends VUE {
// Non-indexed registers // Non-indexed registers
if (system) switch (index) { if (system) switch (index) {
case VUE.JUMP_FROM: return case Vue.JUMP_FROM: return
cpu.jumpFrom[cpu.psw_np != 0 ? 2 : cpu.psw_ep]; 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]; cpu.jumpTo [cpu.psw_np != 0 ? 2 : cpu.psw_ep];
case VUE.PC : return cpu.pc; case Vue.PC : return cpu.pc;
} }
// Indexed registers // Indexed registers
@ -202,7 +202,7 @@ class JavaVUE extends VUE {
// Specify a register value // Specify a register value
public int setRegister(int index, boolean system, int value) { public int setRegister(int index, boolean system, int value) {
return return
index == VUE.PC && system ? cpu.pc = value & 0xFFFFFFFE : index == Vue.PC && system ? cpu.pc = value & 0xFFFFFFFE :
index < 0 || index > 31 ? 0 : index < 0 || index > 31 ? 0 :
system ? cpu.setSystemRegister(index, value, true) : system ? cpu.setSystemRegister(index, value, true) :
index == 0 ? 0 : (cpu.program[index] = value) index == 0 ? 0 : (cpu.program[index] = value)
@ -285,16 +285,16 @@ class JavaVUE extends VUE {
int value = 0; int value = 0;
address &= ~size + 1 & data.length - 1; address &= ~size + 1 & data.length - 1;
switch (type) { switch (type) {
case VUE.S32: value = case Vue.S32: value =
data[address + 3] << 24 | data[address + 3] << 24 |
(data[address + 2] & 0xFF) << 16; (data[address + 2] & 0xFF) << 16;
// Fallthrough // Fallthrough
case VUE.S16: // Fallthrough case Vue.S16: // Fallthrough
case VUE.U16: value |= case Vue.U16: value |=
(data[address + 1] & 0xFF) << 8; (data[address + 1] & 0xFF) << 8;
// Fallthrough // Fallthrough
case VUE.S8 : // Fallthrough case Vue.S8 : // Fallthrough
case VUE.U8 : value |= case Vue.U8 : value |=
data[address ] & 0xFF; data[address ] & 0xFF;
} }
@ -340,16 +340,16 @@ class JavaVUE extends VUE {
int size = TYPE_SIZES[type]; int size = TYPE_SIZES[type];
address &= ~size + 1 & data.length - 1; address &= ~size + 1 & data.length - 1;
switch (type) { switch (type) {
case VUE.S32: case Vue.S32:
data[address + 3] = (byte) (value >> 24); data[address + 3] = (byte) (value >> 24);
data[address + 2] = (byte) (value >> 16); data[address + 2] = (byte) (value >> 16);
// Fallthrough // Fallthrough
case VUE.S16: // Fallthrough case Vue.S16: // Fallthrough
case VUE.U16: case Vue.U16:
data[address + 1] = (byte) (value >> 8); data[address + 1] = (byte) (value >> 8);
// Fallthrough // Fallthrough
case VUE.S8 : // Fallthrough case Vue.S8 : // Fallthrough
case VUE.U8 : value |= case Vue.U8 : value |=
data[address ] = (byte) 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 <math.h>
#include <jni.h> #include <jni.h>
#include <vue.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 { typedef struct {
int32_t type; int32_t type;
int32_t value; int32_t value;
} TOKEN; } Token;
// Precompiled breakpoint // Precompiled breakpoint
typedef struct { typedef struct {
@ -34,16 +34,16 @@ typedef struct {
int32_t numAddresses; // Number of address ranges int32_t numAddresses; // Number of address ranges
int32_t numCondition; // Number of tokens in condition int32_t numCondition; // Number of tokens in condition
int32_t *addresses; // Address ranges int32_t *addresses; // Address ranges
TOKEN *condition; // Condition tokens in RPN order Token *condition; // Condition tokens in RPN order
} BREAKPOINT; } Breakpoint;
// Core context state type // Core context state type
typedef struct { typedef struct {
VUE vue; // Context into the generic C library Vue vue; // Context into the generic C library
int32_t numBreakpoints; // Number of breakpoints int32_t numBreakpoints; // Number of breakpoints
BREAKPOINT *breakpoints; // Application breakpoints Breakpoint *breakpoints; // Application breakpoints
int32_t *stack; // Expression stack for breakpoints int32_t *stack; // Expression stack for breakpoints
} CORE; } Core;
@ -61,7 +61,7 @@ typedef struct {
// Component Includes // // Component Includes //
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#define NATIVEVUE #define NATIVEVue
#include "Breakpoint.c" #include "Breakpoint.c"
@ -70,15 +70,6 @@ typedef struct {
// Internal Functions // // 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 // Native constructor
JNIEXPORT jbyteArray JNICALL Java_vue_NativeVUE_construct JNIEXPORT jlong JNICALL Java_vue_NativeVue_construct
(JNIEnv *env, jobject vue) { (JNIEnv *env, jobject vue) {
Core *mem[] = { NULL, NULL };
// Produce and initialize a new core context Core *core = mem[0] = calloc(sizeof (Core), 1);
CORE *core = calloc(sizeof (CORE), 1);
vueInitialize(&core->vue); vueInitialize(&core->vue);
vueReset(&core->vue); vueReset(&core->vue);
return *(jlong *)&core;
// 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;
} }
// Release any used resources // Release any used resources
JNIEXPORT void JNICALL Java_vue_NativeVUE_dispose JNIEXPORT void JNICALL Java_vue_NativeVue_dispose
(JNIEnv *env, jobject vue) { (JNIEnv *env, jobject vue, jlong handle) {
CORE *core = GetCore(env, vue); Core *core = *(Core **)&handle;
if (core->vue.pak.rom != NULL) if (core->vue.pak.rom != NULL)
free(core->vue.pak.rom); free(core->vue.pak.rom);
if (core->vue.pak.ram != NULL) if (core->vue.pak.ram != NULL)
@ -115,30 +99,37 @@ JNIEXPORT void JNICALL Java_vue_NativeVUE_dispose
} }
// Process the simulation // Process the simulation
JNIEXPORT jint JNICALL Java_vue_NativeVUE_emulate JNIEXPORT jint JNICALL Java_vue_NativeVue_emulate
(JNIEnv *env, jobject vue, jint maxCycles) { (JNIEnv *env, jobject vue, jlong handle, jint maxCycles) {
CORE *core = GetCore(env, vue); Core *core = *(Core **)&handle;
return vueEmulate(&core->vue, maxCycles); 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 // Retrieve the application break code
JNIEXPORT jint JNICALL Java_vue_NativeVUE_getBreakCode JNIEXPORT jint JNICALL Java_vue_NativeVue_getBreakCode
(JNIEnv *env, jobject vue) { (JNIEnv *env, jobject vue, jlong handle) {
CORE *core = GetCore(env, vue); Core *core = *(Core **)&handle;
return vueGetBreakCode(&core->vue); return vueGetBreakCode(&core->vue);
} }
// Retrieve a register value // Retrieve a register value
JNIEXPORT jint JNICALL Java_vue_NativeVUE_getRegister JNIEXPORT jint JNICALL Java_vue_NativeVue_getRegister
(JNIEnv *env, jobject vue, jint index, jboolean system) { (JNIEnv *env, jobject vue, jlong handle, jint index, jboolean system) {
CORE *core = GetCore(env, vue); Core *core = *(Core **)&handle;
return vueGetRegister(&core->vue, index, system);; return vueGetRegister(&core->vue, index, system);;
} }
// Retrieve a copy of the ROM data // Retrieve a copy of the ROM data
JNIEXPORT jbyteArray JNICALL Java_vue_NativeVUE_getROM JNIEXPORT jbyteArray JNICALL Java_vue_NativeVue_getROM
(JNIEnv *env, jobject vue) { (JNIEnv *env, jobject vue, jlong handle) {
CORE *core = GetCore(env, vue); Core *core = *(Core **)&handle;
// No ROM data // No ROM data
if (core->vue.pak.rom == NULL) if (core->vue.pak.rom == NULL)
@ -153,22 +144,22 @@ JNIEXPORT jbyteArray JNICALL Java_vue_NativeVUE_getROM
} }
// Determine whether the context is native-backed // 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) { (JNIEnv *env, jobject vue) {
return JNI_TRUE; return JNI_TRUE;
} }
// Read a value from the CPU bus // Read a value from the CPU bus
JNIEXPORT jint JNICALL Java_vue_NativeVUE_read JNIEXPORT jint JNICALL Java_vue_NativeVue_read
(JNIEnv *env, jobject vue, jint address, jint type) { (JNIEnv *env, jobject vue, jlong handle, jint address, jint type) {
CORE *core = GetCore(env, vue); Core *core = *(Core **)&handle;
return vueRead(&core->vue, address, type); return vueRead(&core->vue, address, type);
} }
// Read bytes from the CPU bus // Read bytes from the CPU bus
JNIEXPORT jboolean JNICALL Java_vue_NativeVUE_readBytes JNIEXPORT jboolean JNICALL Java_vue_NativeVue_readBytes
(JNIEnv *env, jobject vue, jint address, jbyteArray data, jint offset, (JNIEnv *env, jobject vue, jlong handle, jint address, jbyteArray data,
jint length) { jint offset, jint length) {
// Error checking // Error checking
if ( if (
@ -179,7 +170,7 @@ JNIEXPORT jboolean JNICALL Java_vue_NativeVUE_readBytes
) return JNI_FALSE; ) return JNI_FALSE;
// Perform the operation // Perform the operation
CORE *core = GetCore(env, vue); Core *core = *(Core **)&handle;
jbyte *elems = (*env)->GetByteArrayElements(env, data, NULL); jbyte *elems = (*env)->GetByteArrayElements(env, data, NULL);
vueReadBytes(&core->vue, address, &elems[offset], length); vueReadBytes(&core->vue, address, &elems[offset], length);
(*env)->ReleaseByteArrayElements(env, data, elems, 0); (*env)->ReleaseByteArrayElements(env, data, elems, 0);
@ -187,40 +178,42 @@ JNIEXPORT jboolean JNICALL Java_vue_NativeVUE_readBytes
} }
// Initialize all system components // Initialize all system components
JNIEXPORT void JNICALL Java_vue_NativeVUE_reset JNIEXPORT void JNICALL Java_vue_NativeVue_reset
(JNIEnv *env, jobject vue) { (JNIEnv *env, jobject vue, jlong handle) {
CORE *core = GetCore(env, vue); Core *core = *(Core **)&handle;
vueReset(&core->vue); vueReset(&core->vue);
} }
// Specify an exception breakpoint callback // Specify an exception breakpoint callback
JNIEXPORT void JNICALL Java_vue_NativeVUE_setException JNIEXPORT void JNICALL Java_vue_NativeVue_setException
(JNIEnv *env, jobject vue, jobject onException) { (JNIEnv *env, jobject vue, jlong handle, jobject onException) {
CORE *core = GetCore(env, vue); Core *core = *(Core **)&handle;
} }
// Specify an execute breakpoint callback // Specify an execute breakpoint callback
JNIEXPORT void JNICALL Java_vue_NativeVUE_setExecute JNIEXPORT void JNICALL Java_vue_NativeVue_setExecute
(JNIEnv *env, jobject vue, jobject onExecute) { (JNIEnv *env, jobject vue, jlong handle, jobject onExecute) {
CORE *core = GetCore(env, vue); Core *core = *(Core **)&handle;
} }
// Specify a read breakpoint callback // Specify a read breakpoint callback
JNIEXPORT void JNICALL Java_vue_NativeVUE_setRead JNIEXPORT void JNICALL Java_vue_NativeVue_setRead
(JNIEnv *env, jobject vue, jobject onRead) { (JNIEnv *env, jobject vue, jlong handle, jobject onRead) {
CORE *core = GetCore(env, vue); Core *core = *(Core **)&handle;
} }
// Specify a register value // Specify a register value
JNIEXPORT jint JNICALL Java_vue_NativeVUE_setRegister JNIEXPORT jint JNICALL Java_vue_NativeVue_setRegister
(JNIEnv *env, jobject vue, jint index, jboolean system, jint value) { (JNIEnv *env, jobject vue, jlong handle, jint index, jboolean system,
CORE *core = GetCore(env, vue); jint value) {
Core *core = *(Core **)&handle;
return vueSetRegister(&core->vue, index, system, value); return vueSetRegister(&core->vue, index, system, value);
} }
// Provide new ROM data // Provide new ROM data
JNIEXPORT jboolean JNICALL Java_vue_NativeVUE_setROM JNIEXPORT jboolean JNICALL Java_vue_NativeVue_setROM
(JNIEnv *env, jobject vue, jbyteArray data, jint offset, jint length) { (JNIEnv *env, jobject vue, jlong handle, jbyteArray data, jint offset,
jint length) {
// Error checking // Error checking
if ( if (
@ -238,7 +231,7 @@ JNIEXPORT jboolean JNICALL Java_vue_NativeVUE_setROM
(*env)->ReleaseByteArrayElements(env, data, elems, 0); (*env)->ReleaseByteArrayElements(env, data, elems, 0);
// Transfer the ROM data to the emulation state // Transfer the ROM data to the emulation state
CORE *core = GetCore(env, vue); Core *core = *(Core **)&handle;
if (core->vue.pak.rom != NULL) if (core->vue.pak.rom != NULL)
free(core->vue.pak.rom); free(core->vue.pak.rom);
vueSetROM(&core->vue, rom, length); vueSetROM(&core->vue, rom, length);
@ -246,22 +239,23 @@ JNIEXPORT jboolean JNICALL Java_vue_NativeVUE_setROM
} }
// Specify a write breakpoint callback // Specify a write breakpoint callback
JNIEXPORT void JNICALL Java_vue_NativeVUE_setWrite JNIEXPORT void JNICALL Java_vue_NativeVue_setWrite
(JNIEnv *env, jobject vue, jobject onWrite) { (JNIEnv *env, jobject vue, jlong handle, jobject onWrite) {
CORE *core = GetCore(env, vue); Core *core = *(Core **)&handle;
} }
// Write a value to the CPU bus // Write a value to the CPU bus
JNIEXPORT void JNICALL Java_vue_NativeVUE_write JNIEXPORT void JNICALL Java_vue_NativeVue_write
(JNIEnv *env, jobject vue, jint address, jint type, jint value) { (JNIEnv *env, jobject vue, jlong handle, jint address, jint type,
CORE *core = GetCore(env, vue); jint value) {
Core *core = *(Core **)&handle;
vueWrite(&core->vue, address, type, value); vueWrite(&core->vue, address, type, value);
} }
// Write bytes to the CPU bus // Write bytes to the CPU bus
JNIEXPORT jboolean JNICALL Java_vue_NativeVUE_writeBytes JNIEXPORT jboolean JNICALL Java_vue_NativeVue_writeBytes
(JNIEnv *env, jobject vue, jint address, jbyteArray data, jint offset, (JNIEnv *env, jobject vue, jlong handle, jint address, jbyteArray data,
jint length) { jint offset, jint length) {
// Error checking // Error checking
if ( if (
@ -272,7 +266,7 @@ JNIEXPORT jboolean JNICALL Java_vue_NativeVUE_writeBytes
) return JNI_FALSE; ) return JNI_FALSE;
// Perform the operation // Perform the operation
CORE *core = GetCore(env, vue); Core *core = *(Core **)&handle;
jbyte *elems = (*env)->GetByteArrayElements(env, data, NULL); jbyte *elems = (*env)->GetByteArrayElements(env, data, NULL);
vueWriteBytes(&core->vue, address, &elems[offset], length); vueWriteBytes(&core->vue, address, &elems[offset], length);
(*env)->ReleaseByteArrayElements(env, data, elems, 0); (*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; package vue;
// Template for emulation core implementations // Template for emulation core implementations
public abstract class VUE { public abstract class Vue {
// Static fields // Static fields
private static String nativeID = null; // ID of loaded native library private static String nativeID = null; // ID of loaded native library
@ -12,10 +12,10 @@ public abstract class VUE {
// Types // // Types //
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
public interface OnException { int call(VUE vue, Ecxeption exp ); } public interface OnException { int call(Vue vue, Ecxeption exp ); }
public interface OnExecute { int call(VUE vue, Instruction inst ); } public interface OnExecute { int call(Vue vue, Instruction inst ); }
public interface OnRead { int call(VUE vue, Access access); } public interface OnRead { int call(Vue vue, Access access); }
public interface OnWrite { 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 // Produce an emulation core context
public static VUE create(boolean useNative) { public static Vue create(boolean useNative) {
return !useNative ? new JavaVUE() : return !useNative ? new JavaVue() :
isNativeLoaded() ? new NativeVUE() : null; isNativeLoaded() ? new NativeVue() : null;
} }
// Retrieve the ID of the loaded native library, if any // 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 // Specify the ID of the loaded native library
public static void setNativeID(String nativeID) { public static void setNativeID(String nativeID) {
VUE.nativeID = nativeID; Vue.nativeID = nativeID;
} }
@ -167,6 +167,12 @@ public abstract class VUE {
// Public Methods // // Public Methods //
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Attach a breakpoint
//public abstract boolean attachBreakpoint(Breakpoint brk);
// Detach a breakpoint
//public abstract boolean detachBreakpoint(Breakpoint brk);
// Release any used resources // Release any used resources
public abstract void dispose(); public abstract void dispose();
@ -198,24 +204,12 @@ public abstract class VUE {
// Initialize all system components // Initialize all system components
public abstract void reset(); 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 // Specify a register value
public abstract int setRegister(int index, boolean system, int value); public abstract int setRegister(int index, boolean system, int value);
// Provide new ROM data // Provide new ROM data
public abstract boolean setROM(byte[] data, int offset, int length); 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 // Write a value to the CPU bus
public abstract void write(int address, int type, int value); public abstract void write(int address, int type, int value);