Tweaks in preparation for web module
This commit is contained in:
@@ -319,9 +319,10 @@ struct VB {
|
||||
struct {
|
||||
float i1[2]; /* Previous analog input sample */
|
||||
float o1[2]; /* Previous analog output sample */
|
||||
uint32_t capacity; /* Number of audio frames in samples */
|
||||
uint32_t offset; /* Position in output buffer */
|
||||
int16_t *samples; /* Output memory */
|
||||
unsigned capacity; /* Number of audio frames in output buffer */
|
||||
unsigned offset; /* Position in output buffer */
|
||||
void *samples; /* Output buffer */
|
||||
int type; /* Output data type */
|
||||
} out;
|
||||
|
||||
/* Memory */
|
||||
@@ -461,19 +462,23 @@ VBAPI int vbEmulate(VB *sim, uint32_t *clocks) {
|
||||
}
|
||||
|
||||
/* Process multiple simulations */
|
||||
VBAPI int vbEmulateEx(VB **sims, int count, uint32_t *clocks) {
|
||||
VBAPI int vbEmulateEx(VB **sims, unsigned count, uint32_t *clocks) {
|
||||
int brk; /* A callback requested a break */
|
||||
uint32_t until; /* Clocks guaranteed to process */
|
||||
int x; /* Iterator */
|
||||
unsigned x; /* Iterator */
|
||||
|
||||
/* Process one simulation */
|
||||
if (count == 1)
|
||||
return vbEmulate(sims[0], clocks);
|
||||
|
||||
/* Process multiple simulations */
|
||||
while (*clocks != 0) {
|
||||
until = *clocks;
|
||||
for (x = count - 1; x >= 0; x--)
|
||||
until = sysUntil(sims[x], until);
|
||||
|
||||
for (x = count; x > 0; x--)
|
||||
until = sysUntil(sims[x - 1], until);
|
||||
brk = 0;
|
||||
for (x = count - 1; x >= 0; x--)
|
||||
brk |= sysEmulate(sims[x], until);
|
||||
|
||||
for (x = count; x > 0; x--)
|
||||
brk |= sysEmulate(sims[x - 1], until);
|
||||
*clocks -= until;
|
||||
if (brk)
|
||||
return brk; /* TODO: return 1 */
|
||||
@@ -584,7 +589,7 @@ VBAPI uint32_t vbGetProgramCounter(VB *sim) {
|
||||
}
|
||||
|
||||
/* Retrieve the value in a program register */
|
||||
VBAPI int32_t vbGetProgramRegister(VB *sim, int index) {
|
||||
VBAPI int32_t vbGetProgramRegister(VB *sim, unsigned index) {
|
||||
return index < 1 || index > 31 ? 0 : sim->cpu.program[index];
|
||||
}
|
||||
|
||||
@@ -594,13 +599,18 @@ VBAPI vbOnRead vbGetReadCallback(VB *sim) {
|
||||
}
|
||||
|
||||
/* Retrieve the audio samples buffer */
|
||||
VBAPI void* vbGetSamples(VB *sim, uint32_t *capacity, uint32_t *position) {
|
||||
VBAPI void* vbGetSamples(VB *sim, int *type,
|
||||
unsigned *capacity, unsigned *position) {
|
||||
if (sim->vsu.out.samples == NULL) {
|
||||
if (type != NULL)
|
||||
*type = 0;
|
||||
if (capacity != NULL)
|
||||
*capacity = 0;
|
||||
if (position != NULL)
|
||||
*position = 0;
|
||||
} else {
|
||||
if (type != NULL)
|
||||
*type = sim->vsu.out.type;
|
||||
if (capacity != NULL)
|
||||
*capacity = sim->vsu.out.capacity;
|
||||
if (position != NULL)
|
||||
@@ -615,8 +625,8 @@ VBAPI vbOnSamples vbGetSamplesCallback(VB *sim) {
|
||||
}
|
||||
|
||||
/* Retrieve the value in a system register */
|
||||
VBAPI uint32_t vbGetSystemRegister(VB *sim, int index) {
|
||||
return index < 0 || index > 31 ? 0 : cpuGetSystemRegister(sim, index);
|
||||
VBAPI uint32_t vbGetSystemRegister(VB *sim, unsigned index) {
|
||||
return index > 31 ? 0 : cpuGetSystemRegister(sim, index);
|
||||
}
|
||||
|
||||
/* Retrieve a simulation's userdata pointer */
|
||||
@@ -761,12 +771,15 @@ VBAPI int vbSetOption(VB *sim, int key, int value) {
|
||||
}
|
||||
|
||||
/* Specify a new communication peer */
|
||||
VBAPI VB* vbSetPeer(VB *sim, VB *peer) {
|
||||
VB *prev = sim->peer;
|
||||
VBAPI void vbSetPeer(VB *sim, VB *peer) {
|
||||
if (sim->peer == peer)
|
||||
return;
|
||||
sim->peer = peer;
|
||||
if (peer != prev && prev != NULL)
|
||||
prev->peer = NULL;
|
||||
return prev;
|
||||
if (peer == NULL)
|
||||
return;
|
||||
if (peer->peer != NULL)
|
||||
peer->peer->peer = NULL;
|
||||
peer->peer = sim;
|
||||
}
|
||||
|
||||
/* Specify a new value for the program counter */
|
||||
@@ -778,7 +791,7 @@ VBAPI uint32_t vbSetProgramCounter(VB *sim, uint32_t value) {
|
||||
}
|
||||
|
||||
/* Specify a new value for a program register */
|
||||
VBAPI int32_t vbSetProgramRegister(VB *sim, int index, int32_t value) {
|
||||
VBAPI int32_t vbSetProgramRegister(VB *sim, unsigned index, int32_t value) {
|
||||
return index < 1 || index > 31 ? 0 : (sim->cpu.program[index] = value);
|
||||
}
|
||||
|
||||
@@ -790,12 +803,14 @@ VBAPI vbOnRead vbSetReadCallback(VB *sim, vbOnRead callback) {
|
||||
}
|
||||
|
||||
/* Specify a new audio samples buffer */
|
||||
VBAPI int vbSetSamples(VB *sim, void *samples, uint32_t capacity) {
|
||||
if (samples != NULL && (capacity == 0 || capacity > 0x40000000))
|
||||
VBAPI int vbSetSamples(VB *sim, void *samples, int type, unsigned capacity) {
|
||||
if (samples != NULL &&
|
||||
(capacity == 0 || (type != VB_S16 && type != VB_F32)))
|
||||
return 1;
|
||||
sim->vsu.out.capacity = samples == NULL ? 0 : capacity;
|
||||
sim->vsu.out.capacity = capacity;
|
||||
sim->vsu.out.offset = 0;
|
||||
sim->vsu.out.samples = samples;
|
||||
sim->vsu.out.type = type;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -807,9 +822,8 @@ VBAPI vbOnSamples vbSetSamplesCallback(VB *sim, vbOnSamples callback) {
|
||||
}
|
||||
|
||||
/* Specify a new value for a system register */
|
||||
VBAPI uint32_t vbSetSystemRegister(VB *sim, int index, uint32_t value) {
|
||||
return index < 0 || index > 31 ? 0 :
|
||||
cpuSetSystemRegister(sim, index, value, 1);
|
||||
VBAPI uint32_t vbSetSystemRegister(VB *sim, unsigned index, uint32_t value) {
|
||||
return index > 31 ? 0 : cpuSetSystemRegister(sim, index, value, 1);
|
||||
}
|
||||
|
||||
/* Specify a new write callback handler */
|
||||
|
||||
Reference in New Issue
Block a user