CPU corrections

This commit is contained in:
Guy Perfect 2021-09-20 12:51:12 +00:00
parent 573f72e46f
commit 89feaaa3e9
6 changed files with 31 additions and 18 deletions

View File

@ -520,7 +520,7 @@
line : line, line : line,
lines : lines, lines : lines,
target : address, target : address,
seekToPC: seekToPC, seekToPC: !!seekToPC,
size : (end - start + 1) * 4 size : (end - start + 1) * 4
}); });
} }

View File

@ -366,9 +366,9 @@
let bits = this.bits(inst); let bits = this.bits(inst);
let reg2 = this.PROREGNAMES[bits >> 21 & 31]; let reg2 = this.PROREGNAMES[bits >> 21 & 31];
let reg1 = this.PROREGNAMES[bits >> 16 & 31]; let reg1 = this.PROREGNAMES[bits >> 16 & 31];
let subop = this.signExtend(bits & 0xFFFF, 16); let subop = bits >> 10 & 63;
inst.mnemonic = this.FLOATENDO[subop]; inst.mnemonic = this.FLOATENDO[subop];
if (inst.mnemonic = null) if (inst.mnemonic == null)
return; return;
switch (subop) { switch (subop) {
case 0b001000: // XB case 0b001000: // XB

View File

@ -149,6 +149,7 @@ globalThis.MemoryWindow = class MemoryWindow extends Toolkit.Window {
command: "Write", command: "Write",
sim : this.debug.sim, sim : this.debug.sim,
dbgwnd : "Memory", dbgwnd : "Memory",
debug : true,
address: this.selected, address: this.selected,
type : 0, type : 0,
value : value value : value

View File

@ -483,7 +483,7 @@
setRegister(value) { setRegister(value) {
this.debug.core.postMessage({ this.debug.core.postMessage({
command: "SetRegister", command: "SetRegister",
debug : "CPU", dbgwnd : "CPU",
id : this.id, id : this.id,
sim : this.debug.sim, sim : this.debug.sim,
type : this.system ? this.id == -1 ? "pc" : "system" : "program", type : this.system ? this.id == -1 ? "pc" : "system" : "program",

View File

@ -657,7 +657,7 @@ static uint32_t cpuSetSystemRegister(VB *emu,int id,uint32_t value,int debug) {
static int cpuShiftRight(VB *emu, int32_t value, int bits, int arithmetic) { static int cpuShiftRight(VB *emu, int32_t value, int bits, int arithmetic) {
if (bits != 0) { if (bits != 0) {
emu->cpu.psw.cy = (value >> (bits - 1)) & 1; emu->cpu.psw.cy = (value >> (bits - 1)) & 1;
value = value >> bits & (int32_t) 0xFFFFFFFF << bits; value = value >> bits & (((uint32_t) 1 << (32 - bits)) - 1);
if (arithmetic) if (arithmetic)
value = SignExtend(value, 32 - bits); value = SignExtend(value, 32 - bits);
} else emu->cpu.psw.cy = 0; } else emu->cpu.psw.cy = 0;
@ -1064,7 +1064,7 @@ static void cpuMPYHW(VB *emu, VB_INSTRUCTION *inst) {
/* Multiply */ /* Multiply */
static void cpuMUL(VB *emu, VB_INSTRUCTION *inst) { static void cpuMUL(VB *emu, VB_INSTRUCTION *inst) {
int32_t *reg2 = &emu->cpu.program[inst->bits[0] >> 5 & 0xFF]; int32_t *reg2 = &emu->cpu.program[inst->bits[0] >> 5 & 0x1F];
int64_t result = (int64_t) *reg2 * int64_t result = (int64_t) *reg2 *
emu->cpu.program[inst->bits[0] & 0x1F]; emu->cpu.program[inst->bits[0] & 0x1F];
emu->cpu.program[30] = result >> 32; emu->cpu.program[30] = result >> 32;
@ -1095,7 +1095,7 @@ static void cpuMULF_S(VB *emu, VB_INSTRUCTION *inst) {
/* Multiply Unsigned */ /* Multiply Unsigned */
static void cpuMULU(VB *emu, VB_INSTRUCTION *inst) { static void cpuMULU(VB *emu, VB_INSTRUCTION *inst) {
uint32_t *reg2 = (uint32_t *) &emu->cpu.program[inst->bits[0]>>5&0xFF]; uint32_t *reg2 = (uint32_t *) &emu->cpu.program[inst->bits[0]>>5&0x1F];
uint64_t result = (uint64_t) *reg2 * uint64_t result = (uint64_t) *reg2 *
(uint32_t) emu->cpu.program[inst->bits[0] & 0x1F]; (uint32_t) emu->cpu.program[inst->bits[0] & 0x1F];
emu->cpu.program[30] = result >> 32; emu->cpu.program[30] = result >> 32;
@ -1182,11 +1182,12 @@ static void cpuRETI(VB *emu, VB_INSTRUCTION *inst) {
/* Reverse Bits in Word */ /* Reverse Bits in Word */
static void cpuREV(VB *emu, VB_INSTRUCTION *inst) { static void cpuREV(VB *emu, VB_INSTRUCTION *inst) {
int32_t value = emu->cpu.program[inst->bits[0] & 0x1F]; int32_t value = emu->cpu.program[inst->bits[0] & 0x1F];
value = (value >> 8 & 0x00FF00FF) | (value << 8 & (int32_t) 0xFF00FF00); value = (value >> 16 & 0x0000FFFF) | (value << 16 & (int32_t) 0xFFFF0000);
value = (value >> 4 & 0x0F0F0F0F) | (value << 4 & (int32_t) 0xF0F0F0F0); value = (value >> 8 & 0x00FF00FF) | (value << 8 & (int32_t) 0xFF00FF00);
value = (value >> 2 & 0x33333333) | (value << 2 & (int32_t) 0xCCCCCCCC); value = (value >> 4 & 0x0F0F0F0F) | (value << 4 & (int32_t) 0xF0F0F0F0);
value = (value >> 2 & 0x33333333) | (value << 2 & (int32_t) 0xCCCCCCCC);
emu->cpu.program[inst->bits[0] >> 5 & 0x1F] = emu->cpu.program[inst->bits[0] >> 5 & 0x1F] =
(value >> 1 & 0x55555555) | (value << 1 & (int32_t) 0xAAAAAAAA); (value >> 1 & 0x55555555) | (value << 1 & (int32_t) 0xAAAAAAAA);
emu->cpu.clocks = 22; emu->cpu.clocks = 22;
} }
@ -1311,9 +1312,9 @@ static void cpuTRAP(VB *emu, VB_INSTRUCTION *inst) {
static void cpuXB(VB *emu, VB_INSTRUCTION *inst) { static void cpuXB(VB *emu, VB_INSTRUCTION *inst) {
int32_t *reg2 = &emu->cpu.program[inst->bits[0] >> 5 & 0x1F]; int32_t *reg2 = &emu->cpu.program[inst->bits[0] >> 5 & 0x1F];
*reg2 = *reg2 =
(*reg2 >> 8 & (int32_t) 0x00FF0000) | (*reg2 >> 8 & (int32_t) 0x000000FF) |
(*reg2 << 8 & (int32_t) 0xFF000000) | (*reg2 << 8 & (int32_t) 0x0000FF00) |
(*reg2 & (int32_t) 0x0000FFFF) (*reg2 & (int32_t) 0xFFFF0000)
; ;
emu->cpu.clocks = 6; emu->cpu.clocks = 6;
} }
@ -1378,8 +1379,18 @@ static int cpuCheckIRQs(VB *emu) {
/* Perform instruction execute operations */ /* Perform instruction execute operations */
static int cpuExecute(VB *emu) { static int cpuExecute(VB *emu) {
int broke = 0; /* Application break occurred */ int broke; /* Application break occurred */
VB_INSTRUCTION *inst = &emu->cpu.inst; /* Shorthand reference */ VB_INSTRUCTION *inst; /* Shorthand reference */
/* Check for address trap */
if (emu->cpu.psw.ae && emu->cpu.adtre == emu->cpu.pc) {
emu->cpu.causeCode = 0xFFC0;
emu->cpu.state = CPU_EXCEPTION;
return 0;
}
/* Working variables */
inst = &emu->cpu.inst;
/* Check for application break */ /* Check for application break */
if (emu->onExecute != NULL && emu->onExecute(emu, inst)) if (emu->onExecute != NULL && emu->onExecute(emu, inst))
@ -1389,6 +1400,7 @@ static int cpuExecute(VB *emu) {
emu->cpu.causeCode = 0; emu->cpu.causeCode = 0;
/* Processing by ID */ /* Processing by ID */
broke = 0;
switch (inst->id) { switch (inst->id) {
case CPU_ADD_IMM: cpuADD_IMM(emu, inst); break; case CPU_ADD_IMM: cpuADD_IMM(emu, inst); break;
case CPU_ADD_REG: cpuADD_REG(emu, inst); break; case CPU_ADD_REG: cpuADD_REG(emu, inst); break;
@ -1651,7 +1663,7 @@ static int cpuFetch(VB *emu) {
} }
/* Update state */ /* Update state */
emu->cpu.fetch = -1; emu->cpu.fetch = 0;
emu->cpu.state = CPU_EXECUTE; emu->cpu.state = CPU_EXECUTE;
return 0; return 0;
} }

View File

@ -1,7 +1,7 @@
.PHONY: help .PHONY: help
help: help:
@echo @echo
@echo "Virtual Boy Emulator - September 19, 2021" @echo "Virtual Boy Emulator - September 20, 2021"
@echo @echo
@echo "Target build environment is any Debian with the following packages:" @echo "Target build environment is any Debian with the following packages:"
@echo " emscripten" @echo " emscripten"