Tweaks from concurrent project
This commit is contained in:
parent
a7985bad6e
commit
fccb799a9c
30
core/cpu.c
30
core/cpu.c
|
@ -202,6 +202,7 @@ static int cpuWrite(VB *emu, uint32_t address, int8_t type, int32_t value) {
|
||||||
|
|
||||||
/* Using a breakpoint callback */
|
/* Using a breakpoint callback */
|
||||||
if (emu->onWrite != NULL) {
|
if (emu->onWrite != NULL) {
|
||||||
|
emu->cpu.access.address = address;
|
||||||
emu->cpu.access.value = value;
|
emu->cpu.access.value = value;
|
||||||
if (emu->onWrite(emu, &emu->cpu.access))
|
if (emu->onWrite(emu, &emu->cpu.access))
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -234,7 +235,7 @@ static int cpuBitSearch(VB *emu, int32_t bit, int32_t dir) {
|
||||||
int32_t value; /* Alias of source word */
|
int32_t value; /* Alias of source word */
|
||||||
|
|
||||||
/* Read the source word */
|
/* Read the source word */
|
||||||
if (!emu->cpu.busWait) {
|
if (emu->cpu.busWait == 0) {
|
||||||
|
|
||||||
/* Initialize state */
|
/* Initialize state */
|
||||||
emu->cpu.program[30] &= 0xFFFFFFFC;
|
emu->cpu.program[30] &= 0xFFFFFFFC;
|
||||||
|
@ -600,7 +601,7 @@ static void cpuJump(VB *emu, VB_INSTRUCTION *inst, uint32_t address) {
|
||||||
static int cpuLoad(VB *emu,VB_INSTRUCTION *inst,uint8_t type,uint32_t clocks) {
|
static int cpuLoad(VB *emu,VB_INSTRUCTION *inst,uint8_t type,uint32_t clocks) {
|
||||||
|
|
||||||
/* Initiate the read */
|
/* Initiate the read */
|
||||||
if (!emu->cpu.busWait) {
|
if (emu->cpu.busWait == 0) {
|
||||||
|
|
||||||
/* Read the data unit from the bus */
|
/* Read the data unit from the bus */
|
||||||
if (cpuRead(
|
if (cpuRead(
|
||||||
|
@ -688,7 +689,7 @@ static int cpuShiftRight(VB *emu, int32_t value, int bits, int arithmetic) {
|
||||||
static int cpuStore(VB *emu,VB_INSTRUCTION *inst,uint8_t type,uint32_t clocks){
|
static int cpuStore(VB *emu,VB_INSTRUCTION *inst,uint8_t type,uint32_t clocks){
|
||||||
|
|
||||||
/* Initiate the write */
|
/* Initiate the write */
|
||||||
if (!emu->cpu.busWait) {
|
if (emu->cpu.busWait == 0) {
|
||||||
|
|
||||||
/* Read the data unit from the bus */
|
/* Read the data unit from the bus */
|
||||||
if (cpuWrite(
|
if (cpuWrite(
|
||||||
|
@ -1000,9 +1001,8 @@ static void cpuDIVU(VB *emu, VB_INSTRUCTION *inst) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Halt */
|
/* Halt */
|
||||||
static void cpuHALT(VB *emu, VB_INSTRUCTION *inst) {
|
static void cpuHALT(VB *emu) {
|
||||||
emu->cpu.state = CPU_HALTED;
|
emu->cpu.state = CPU_HALTED;
|
||||||
inst->size = 0;
|
|
||||||
/* emu->cpu.clocks = ? */
|
/* emu->cpu.clocks = ? */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1413,16 +1413,14 @@ static int cpuExecute(VB *emu) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Working variables */
|
/* Prepare state */
|
||||||
|
emu->cpu.causeCode = 0;
|
||||||
inst = &emu->cpu.inst;
|
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))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* Update state */
|
|
||||||
emu->cpu.causeCode = 0;
|
|
||||||
|
|
||||||
/* Processing by ID */
|
/* Processing by ID */
|
||||||
broke = 0;
|
broke = 0;
|
||||||
switch (inst->id) {
|
switch (inst->id) {
|
||||||
|
@ -1445,7 +1443,7 @@ static int cpuExecute(VB *emu) {
|
||||||
case CPU_DIV : cpuDIV (emu, inst); break;
|
case CPU_DIV : cpuDIV (emu, inst); break;
|
||||||
case CPU_DIVF_S : cpuDIVF_S (emu, inst); break;
|
case CPU_DIVF_S : cpuDIVF_S (emu, inst); break;
|
||||||
case CPU_DIVU : cpuDIVU (emu, inst); break;
|
case CPU_DIVU : cpuDIVU (emu, inst); break;
|
||||||
case CPU_HALT : cpuHALT (emu, inst); break;
|
case CPU_HALT : cpuHALT (emu ); break;
|
||||||
case CPU_IN_B : broke = cpuIN_B (emu, inst); break;
|
case CPU_IN_B : broke = cpuIN_B (emu, inst); break;
|
||||||
case CPU_IN_H : broke = cpuIN_H (emu, inst); break;
|
case CPU_IN_H : broke = cpuIN_H (emu, inst); break;
|
||||||
case CPU_IN_W : broke = cpuIN_W (emu, inst); break;
|
case CPU_IN_W : broke = cpuIN_W (emu, inst); break;
|
||||||
|
@ -1513,7 +1511,7 @@ static int cpuExecute(VB *emu) {
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* Post-instruction tasks */
|
/* Post-instruction tasks */
|
||||||
if (emu->cpu.causeCode == 0 && !emu->cpu.busWait) {
|
if (emu->cpu.causeCode == 0 && emu->cpu.busWait == 0) {
|
||||||
|
|
||||||
/* Advance to next instruction */
|
/* Advance to next instruction */
|
||||||
if (emu->cpu.state != CPU_HALTED && !emu->cpu.substring)
|
if (emu->cpu.state != CPU_HALTED && !emu->cpu.substring)
|
||||||
|
@ -1531,7 +1529,7 @@ static int cpuExecute(VB *emu) {
|
||||||
|
|
||||||
/* Switch to fetch mode */
|
/* Switch to fetch mode */
|
||||||
else if (emu->cpu.state != CPU_HALTED &&
|
else if (emu->cpu.state != CPU_HALTED &&
|
||||||
!emu->cpu.busWait && !emu->cpu.substring) {
|
emu->cpu.busWait == 0 && !emu->cpu.substring) {
|
||||||
emu->cpu.state = CPU_FETCH;
|
emu->cpu.state = CPU_FETCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1642,7 +1640,7 @@ static int cpuFetch(VB *emu) {
|
||||||
uint8_t opcode; /* 6-bit instruction opcode */
|
uint8_t opcode; /* 6-bit instruction opcode */
|
||||||
|
|
||||||
/* Need to read a data unit */
|
/* Need to read a data unit */
|
||||||
if (!emu->cpu.busWait) {
|
if (emu->cpu.busWait == 0) {
|
||||||
|
|
||||||
/* Read the data unit from the bus */
|
/* Read the data unit from the bus */
|
||||||
if (cpuReadFetch(emu, emu->cpu.pc + (emu->cpu.fetch << 1)))
|
if (cpuReadFetch(emu, emu->cpu.pc + (emu->cpu.fetch << 1)))
|
||||||
|
@ -1741,6 +1739,9 @@ static void cpuReset(VB *emu) {
|
||||||
|
|
||||||
/* Other state */
|
/* Other state */
|
||||||
emu->cpu.busWait = 0;
|
emu->cpu.busWait = 0;
|
||||||
|
emu->cpu.causeCode = 0;
|
||||||
|
emu->cpu.clocks = 0;
|
||||||
|
emu->cpu.fetch = 0;
|
||||||
emu->cpu.state = CPU_FETCH;
|
emu->cpu.state = CPU_FETCH;
|
||||||
emu->cpu.substring = 0;
|
emu->cpu.substring = 0;
|
||||||
for (x = 0; x < 5; x++)
|
for (x = 0; x < 5; x++)
|
||||||
|
@ -1775,6 +1776,7 @@ static uint32_t cpuUntil(VB *emu, uint32_t clocks) {
|
||||||
emu->cpu.state == CPU_FATAL || (
|
emu->cpu.state == CPU_FATAL || (
|
||||||
emu->onException == NULL &&
|
emu->onException == NULL &&
|
||||||
emu->onExecute == NULL &&
|
emu->onExecute == NULL &&
|
||||||
|
emu->onFetch == NULL &&
|
||||||
emu->onRead == NULL &&
|
emu->onRead == NULL &&
|
||||||
emu->onWrite == NULL
|
emu->onWrite == NULL
|
||||||
)) return clocks;
|
)) return clocks;
|
||||||
|
@ -1785,4 +1787,4 @@ static uint32_t cpuUntil(VB *emu, uint32_t clocks) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* VBAPI */
|
#endif /* WSAPI */
|
||||||
|
|
32
core/vb.c
32
core/vb.c
|
@ -98,6 +98,22 @@ int vbEmulate(VB *emu1, VB *emu2, uint32_t *clocks) {
|
||||||
return broke;
|
return broke;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Retrieve a current breakpoint callback */
|
||||||
|
void* vbGetCallback(VB *emu, int type) {
|
||||||
|
/* -Wpedantic ignored for pointer conversion because no alternative */
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wpedantic"
|
||||||
|
switch (type) {
|
||||||
|
case VB_ONEXCEPTION: return emu->onException;
|
||||||
|
case VB_ONEXECUTE : return emu->onExecute;
|
||||||
|
case VB_ONFETCH : return emu->onFetch;
|
||||||
|
case VB_ONREAD : return emu->onRead;
|
||||||
|
case VB_ONWRITE : return emu->onWrite;
|
||||||
|
}
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Retrieve the value of PC */
|
/* Retrieve the value of PC */
|
||||||
uint32_t vbGetProgramCounter(VB *emu, int type) {
|
uint32_t vbGetProgramCounter(VB *emu, int type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
@ -205,9 +221,25 @@ void vbReset(VB *emu) {
|
||||||
emu->wram[x] = 0x00;
|
emu->wram[x] = 0x00;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Specify a breakpoint callback */
|
||||||
|
void vbSetCallback(VB *emu, int type, void *callback) {
|
||||||
|
/* -Wpedantic ignored for pointer conversion because no alternative */
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wpedantic"
|
||||||
|
switch (type) {
|
||||||
|
case VB_ONEXCEPTION: emu->onException=(VB_EXCEPTIONPROC)callback;break;
|
||||||
|
case VB_ONEXECUTE : emu->onExecute =(VB_EXECUTEPROC )callback;break;
|
||||||
|
case VB_ONFETCH : emu->onFetch =(VB_FETCHPROC )callback;break;
|
||||||
|
case VB_ONREAD : emu->onRead =(VB_READPROC )callback;break;
|
||||||
|
case VB_ONWRITE : emu->onWrite =(VB_WRITEPROC )callback;break;
|
||||||
|
}
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
}
|
||||||
|
|
||||||
/* Specify a new value for PC */
|
/* Specify a new value for PC */
|
||||||
uint32_t vbSetProgramCounter(VB *emu, uint32_t value) {
|
uint32_t vbSetProgramCounter(VB *emu, uint32_t value) {
|
||||||
value &= 0xFFFFFFFE;
|
value &= 0xFFFFFFFE;
|
||||||
|
emu->cpu.causeCode = 0;
|
||||||
emu->cpu.fetch = 0;
|
emu->cpu.fetch = 0;
|
||||||
emu->cpu.pc = value;
|
emu->cpu.pc = value;
|
||||||
emu->cpu.state = CPU_FETCH;
|
emu->cpu.state = CPU_FETCH;
|
||||||
|
|
11
core/vb.h
11
core/vb.h
|
@ -42,6 +42,13 @@ extern "C" {
|
||||||
#define VB_PC_FROM 1
|
#define VB_PC_FROM 1
|
||||||
#define VB_PC_TO 2
|
#define VB_PC_TO 2
|
||||||
|
|
||||||
|
/* Breakpoint callback types */
|
||||||
|
#define VB_ONEXCEPTION 0
|
||||||
|
#define VB_ONEXECUTE 1
|
||||||
|
#define VB_ONFETCH 2
|
||||||
|
#define VB_ONREAD 3
|
||||||
|
#define VB_ONWRITE 4
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*********************************** Types ***********************************/
|
/*********************************** Types ***********************************/
|
||||||
|
@ -146,7 +153,7 @@ struct VB {
|
||||||
VB_ACCESS access; /* Memory access descriptor */
|
VB_ACCESS access; /* Memory access descriptor */
|
||||||
VB_INSTRUCTION inst; /* Instruction descriptor */
|
VB_INSTRUCTION inst; /* Instruction descriptor */
|
||||||
uint8_t irq[5]; /* Interrupt request lines */
|
uint8_t irq[5]; /* Interrupt request lines */
|
||||||
uint8_t busWait; /* Waiting on a memory access */
|
uint8_t busWait; /* Memory access counter */
|
||||||
uint16_t causeCode; /* Exception cause code */
|
uint16_t causeCode; /* Exception cause code */
|
||||||
uint32_t clocks; /* Clocks until next action */
|
uint32_t clocks; /* Clocks until next action */
|
||||||
int16_t fetch; /* Index of fetch unit */
|
int16_t fetch; /* Index of fetch unit */
|
||||||
|
@ -173,6 +180,7 @@ struct VB {
|
||||||
VBAPI void vbConnect (VB *emu1, VB *emu2);
|
VBAPI void vbConnect (VB *emu1, VB *emu2);
|
||||||
VBAPI void vbDisconnect (VB *emu);
|
VBAPI void vbDisconnect (VB *emu);
|
||||||
VBAPI int vbEmulate (VB *emu1, VB *emu2, uint32_t *clocks);
|
VBAPI int vbEmulate (VB *emu1, VB *emu2, uint32_t *clocks);
|
||||||
|
VBAPI void* vbGetCallback (VB *emu, int type);
|
||||||
VBAPI uint32_t vbGetProgramCounter (VB *emu, int type);
|
VBAPI uint32_t vbGetProgramCounter (VB *emu, int type);
|
||||||
VBAPI int32_t vbGetProgramRegister (VB *emu, int id);
|
VBAPI int32_t vbGetProgramRegister (VB *emu, int id);
|
||||||
VBAPI void* vbGetROM (VB *emu, uint32_t *size);
|
VBAPI void* vbGetROM (VB *emu, uint32_t *size);
|
||||||
|
@ -181,6 +189,7 @@ VBAPI uint32_t vbGetSystemRegister (VB *emu, int id);
|
||||||
VBAPI void vbInit (VB *emu);
|
VBAPI void vbInit (VB *emu);
|
||||||
VBAPI int32_t vbRead (VB *emu, uint32_t address, int type, int debug);
|
VBAPI int32_t vbRead (VB *emu, uint32_t address, int type, int debug);
|
||||||
VBAPI void vbReset (VB *emu);
|
VBAPI void vbReset (VB *emu);
|
||||||
|
VBAPI void vbSetCallback (VB *emu, int type, void *callback);
|
||||||
VBAPI uint32_t vbSetProgramCounter (VB *emu, uint32_t value);
|
VBAPI uint32_t vbSetProgramCounter (VB *emu, uint32_t value);
|
||||||
VBAPI int32_t vbSetProgramRegister (VB *emu, int id, int32_t value);
|
VBAPI int32_t vbSetProgramRegister (VB *emu, int id, int32_t value);
|
||||||
VBAPI int vbSetROM (VB *emu, void *rom, uint32_t size);
|
VBAPI int vbSetROM (VB *emu, void *rom, uint32_t size);
|
||||||
|
|
2
makefile
2
makefile
|
@ -1,7 +1,7 @@
|
||||||
.PHONY: help
|
.PHONY: help
|
||||||
help:
|
help:
|
||||||
@echo
|
@echo
|
||||||
@echo "Virtual Boy Emulator - September 20, 2021"
|
@echo "Virtual Boy Emulator - September 30, 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"
|
||||||
|
|
Loading…
Reference in New Issue