Tweaks from concurrent project
This commit is contained in:
+9
-9
@@ -6,7 +6,7 @@
|
||||
/***************************** Utility Functions *****************************/
|
||||
|
||||
/* Read a data unit from a memory buffer */
|
||||
static int32_t busReadMemory(uint8_t *mem, int type) {
|
||||
static int32_t busReadBuffer(uint8_t *mem, int type) {
|
||||
|
||||
/* Little-endian implementation */
|
||||
#ifdef VB_LITTLEENDIAN
|
||||
@@ -33,7 +33,7 @@ static int32_t busReadMemory(uint8_t *mem, int type) {
|
||||
}
|
||||
|
||||
/* Write a data unit to a memory buffer */
|
||||
static void busWriteMemory(uint8_t *mem, int type, int32_t value) {
|
||||
static void busWriteBuffer(uint8_t *mem, int type, int32_t value) {
|
||||
|
||||
/* Little-endian implementation */
|
||||
#ifdef VB_LITTLEENDIAN
|
||||
@@ -72,17 +72,17 @@ static int32_t busRead(VB *sim, uint32_t address, int type, int debug) {
|
||||
/* Process by address range */
|
||||
switch (address >> 24 & 7) {
|
||||
case 0 : return 0; /* VIP */
|
||||
case 1 : debug = debug; return 0; /* VSU */
|
||||
case 1 : return 0 * debug; /* VSU */
|
||||
case 2 : return 0; /* Miscellaneous hardware */
|
||||
case 3 : return 0; /* Unmapped */
|
||||
case 4 : return 0; /* Game pak expansion */
|
||||
case 5 : return /* WRAM */
|
||||
busReadMemory(&sim->wram[address & 0xFFFF], type);
|
||||
busReadBuffer(&sim->wram[address & 0xFFFF], type);
|
||||
case 6 : return sim->cart.sram == NULL ? 0 : /* Game pak RAM */
|
||||
busReadMemory(&sim->cart.sram
|
||||
busReadBuffer(&sim->cart.sram
|
||||
[address & (sim->cart.sramSize - 1)], type);
|
||||
default: return sim->cart.rom == NULL ? 0 : /* Game pak ROM */
|
||||
busReadMemory(&sim->cart.rom
|
||||
busReadBuffer(&sim->cart.rom
|
||||
[address & (sim->cart.romSize - 1)], type);
|
||||
}
|
||||
|
||||
@@ -103,16 +103,16 @@ static void busWrite(
|
||||
case 3 : return; /* Unmapped */
|
||||
case 4 : return; /* Game pak expansion */
|
||||
case 5 : /* WRAM */
|
||||
busWriteMemory(&sim->wram[address & 0xFFFF], type, value);
|
||||
busWriteBuffer(&sim->wram[address & 0xFFFF], type, value);
|
||||
return;
|
||||
case 6 : /* Cartridge RAM */
|
||||
if (sim->cart.sram != NULL)
|
||||
busWriteMemory(&sim->cart.sram
|
||||
busWriteBuffer(&sim->cart.sram
|
||||
[address & (sim->cart.sramSize - 1)], type, value);
|
||||
return;
|
||||
default: /* Cartridge ROM */
|
||||
if (debug && sim->cart.rom != NULL)
|
||||
busWriteMemory(&sim->cart.rom
|
||||
busWriteBuffer(&sim->cart.rom
|
||||
[address & (sim->cart.romSize - 1)], type, value);
|
||||
}
|
||||
|
||||
|
||||
+6
-7
@@ -646,12 +646,11 @@ static uint32_t cpuSetSystemRegister(VB *sim,int id,uint32_t value,int debug) {
|
||||
/* TODO: Perform dump/restore operations */
|
||||
return value & 0x00000002;
|
||||
case VB_ECR :
|
||||
if (debug) {
|
||||
sim->cpu.ecr.fecc = value >> 16;
|
||||
sim->cpu.ecr.eicc = value;
|
||||
return value;
|
||||
}
|
||||
return vbGetSystemRegister(sim, id);
|
||||
if (!debug)
|
||||
return (uint32_t) sim->cpu.ecr.fecc << 16 | sim->cpu.ecr.eicc;
|
||||
sim->cpu.ecr.fecc = value >> 16;
|
||||
sim->cpu.ecr.eicc = value;
|
||||
return value;
|
||||
case VB_PSW :
|
||||
sim->cpu.psw.i = value >> 16 & 15;
|
||||
sim->cpu.psw.np = value >> 15 & 1;
|
||||
@@ -690,7 +689,7 @@ static int cpuStore(VB *sim,VB_INSTRUCTION *inst,uint8_t type,uint32_t clocks){
|
||||
/* Initiate the write */
|
||||
if (sim->cpu.busWait == 0) {
|
||||
|
||||
/* Read the data unit from the bus */
|
||||
/* Write the data unit to the bus */
|
||||
if (cpuWrite(
|
||||
sim,
|
||||
sim->cpu.program[inst->bits[0] & 0x1F] +
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
#define VBAPI VB_EXPORT
|
||||
#ifdef VB_EXPORT
|
||||
#define VBAPI VB_EXPORT
|
||||
#else
|
||||
#define VBAPI
|
||||
#endif
|
||||
|
||||
/* Header includes */
|
||||
#include <float.h>
|
||||
@@ -50,36 +54,31 @@ static uint32_t sysUntil(VB *sim, uint32_t clocks) {
|
||||
/******************************* API Functions *******************************/
|
||||
|
||||
/* Associate two simulations as peers, or remove an association */
|
||||
void vbConnect(VB *a, VB *b) {
|
||||
void vbConnect(VB *sim1, VB *sim2) {
|
||||
|
||||
/* Disconnect */
|
||||
if (b == NULL) {
|
||||
if (a->peer != NULL)
|
||||
a->peer->peer = NULL;
|
||||
a->peer = NULL;
|
||||
if (sim2 == NULL) {
|
||||
if (sim1->peer != NULL)
|
||||
sim1->peer->peer = NULL;
|
||||
sim1->peer = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
/* The simulations are already linked */
|
||||
if (a->peer == b && b->peer == a)
|
||||
return;
|
||||
|
||||
/* Disconnect any existing link associations */
|
||||
if (a->peer != NULL && a->peer != b)
|
||||
a->peer->peer = NULL;
|
||||
if (b->peer != NULL && b->peer != a)
|
||||
b->peer->peer = NULL;
|
||||
if (sim1->peer != NULL && sim1->peer != sim2)
|
||||
sim1->peer->peer = NULL;
|
||||
if (sim2->peer != NULL && sim2->peer != sim1)
|
||||
sim2->peer->peer = NULL;
|
||||
|
||||
/* Link the two simulations */
|
||||
a->peer = b;
|
||||
b->peer = a;
|
||||
sim1->peer = sim2;
|
||||
sim2->peer = sim1;
|
||||
}
|
||||
|
||||
/* Process one simulation */
|
||||
int vbEmulate(VB *sim, uint32_t *clocks) {
|
||||
int broke; /* The simulation requested an application break */
|
||||
uint32_t until; /* Maximum clocks before a break could happen */
|
||||
int x; /* Iterator */
|
||||
|
||||
/* Process the simulation until a break condition occurs */
|
||||
do {
|
||||
@@ -114,18 +113,20 @@ int vbEmulateMulti(VB **sims, int count, uint32_t *clocks) {
|
||||
|
||||
/* Retrieve a current breakpoint callback */
|
||||
void* vbGetCallback(VB *sim, int type) {
|
||||
/* -Wpedantic ignored for pointer conversion because no alternative */
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wpedantic"
|
||||
void **field; /* Pointer to field within simulation */
|
||||
|
||||
/* Select the field to update */
|
||||
switch (type) {
|
||||
case VB_ONEXCEPTION: return sim->onException;
|
||||
case VB_ONEXECUTE : return sim->onExecute;
|
||||
case VB_ONFETCH : return sim->onFetch;
|
||||
case VB_ONREAD : return sim->onRead;
|
||||
case VB_ONWRITE : return sim->onWrite;
|
||||
case VB_ONEXCEPTION: field = (void *) &sim->onException; break;
|
||||
case VB_ONEXECUTE : field = (void *) &sim->onExecute ; break;
|
||||
case VB_ONFETCH : field = (void *) &sim->onFetch ; break;
|
||||
case VB_ONREAD : field = (void *) &sim->onRead ; break;
|
||||
case VB_ONWRITE : field = (void *) &sim->onWrite ; break;
|
||||
default: return NULL;
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
return NULL;
|
||||
|
||||
/* Retrieve the simulation field */
|
||||
return *field;
|
||||
}
|
||||
|
||||
/* Retrieve the value of PC */
|
||||
@@ -231,18 +232,24 @@ void vbReset(VB *sim) {
|
||||
}
|
||||
|
||||
/* Specify a breakpoint callback */
|
||||
void vbSetCallback(VB *sim, int type, void *callback) {
|
||||
/* -Wpedantic ignored for pointer conversion because no alternative */
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wpedantic"
|
||||
void* vbSetCallback(VB *sim, int type, void *callback) {
|
||||
void **field; /* Pointer to field within simulation */
|
||||
void *prev; /* Previous value within field */
|
||||
|
||||
/* Select the field to update */
|
||||
switch (type) {
|
||||
case VB_ONEXCEPTION: sim->onException=(VB_EXCEPTIONPROC)callback;break;
|
||||
case VB_ONEXECUTE : sim->onExecute =(VB_EXECUTEPROC )callback;break;
|
||||
case VB_ONFETCH : sim->onFetch =(VB_FETCHPROC )callback;break;
|
||||
case VB_ONREAD : sim->onRead =(VB_READPROC )callback;break;
|
||||
case VB_ONWRITE : sim->onWrite =(VB_WRITEPROC )callback;break;
|
||||
case VB_ONEXCEPTION: field = (void *) &sim->onException; break;
|
||||
case VB_ONEXECUTE : field = (void *) &sim->onExecute ; break;
|
||||
case VB_ONFETCH : field = (void *) &sim->onFetch ; break;
|
||||
case VB_ONREAD : field = (void *) &sim->onRead ; break;
|
||||
case VB_ONWRITE : field = (void *) &sim->onWrite ; break;
|
||||
return NULL;
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
/* Update the simulation field */
|
||||
prev = *field;
|
||||
*field = callback;
|
||||
return prev;
|
||||
}
|
||||
|
||||
/* Specify a new value for PC */
|
||||
|
||||
@@ -181,7 +181,7 @@ VBAPI uint32_t vbGetSystemRegister (VB *sim, int id);
|
||||
VBAPI void vbInit (VB *sim);
|
||||
VBAPI int32_t vbRead (VB *sim, uint32_t address, int type, int debug);
|
||||
VBAPI void vbReset (VB *sim);
|
||||
VBAPI void vbSetCallback (VB *sim, int type, void *callback);
|
||||
VBAPI void* vbSetCallback (VB *sim, int type, void *callback);
|
||||
VBAPI uint32_t vbSetProgramCounter (VB *sim, uint32_t value);
|
||||
VBAPI int32_t vbSetProgramRegister (VB *sim, int id, int32_t value);
|
||||
VBAPI int vbSetROM (VB *sim, void *rom, uint32_t size);
|
||||
|
||||
Reference in New Issue
Block a user