Compare commits
17
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
57dcd8370a | ||
|
|
06849b54ba | ||
|
|
eef255b507 | ||
|
|
db966c8cb8 | ||
|
|
b4feff41f0 | ||
|
|
4449acada0 | ||
|
|
799ac9f51a | ||
|
|
b83b49221d | ||
|
|
27e926bd58 | ||
|
|
d802d39d8d | ||
|
|
18b2c589e6 | ||
|
|
f45636a491 | ||
|
|
9ce8c9c778 | ||
|
|
c90b8137de | ||
|
|
bc864644f7 | ||
|
|
e97b52e944 | ||
|
|
7e31fbd582 |
+1
-5
@@ -91,11 +91,6 @@
|
||||
#define CPU_XORBSU 82
|
||||
#define CPU_XORNBSU 83
|
||||
|
||||
/* Functional operand types */
|
||||
#define CPU_LITERAL 0
|
||||
#define CPU_MEMORY 1
|
||||
#define CPU_REGISTER 2
|
||||
|
||||
/* Bit string operations */
|
||||
#define CPU_AND_BS 0
|
||||
#define CPU_ANDN_BS 1
|
||||
@@ -1642,6 +1637,7 @@ static void cpuSUBF_S(VB *sim) {
|
||||
/* TRAP */
|
||||
static void cpuTRAP(VB *sim) {
|
||||
sim->cpu.clocks += cpuClocks(15);
|
||||
sim->cpu.pc += 2;
|
||||
cpuThrow(sim, 0xFFA0 + cpuGetImm5U(sim));
|
||||
}
|
||||
|
||||
|
||||
+41
-14
@@ -5,6 +5,15 @@
|
||||
|
||||
/***************************** Module Functions ******************************/
|
||||
|
||||
/* Compute clocks until the next decrement to zero */
|
||||
static uint32_t tmrGetUntil(VB *sim) {
|
||||
uint32_t fullTick = sim->tmr.t_clk_sel ? 400 : 2000;
|
||||
uint32_t thisTick = sim->tmr.clocks +
|
||||
(sim->tmr.t_clk_sel ? 0 : 400 * (4 - sim->tmr.tick20));
|
||||
return thisTick + fullTick *
|
||||
(sim->tmr.counter == 0 ? sim->tmr.reload : sim->tmr.counter - 1);
|
||||
}
|
||||
|
||||
/* Update the counter to a new value */
|
||||
static void tmrUpdate(VB *sim, uint16_t value) {
|
||||
if (value == 0 && sim->tmr.counter != 0) {
|
||||
@@ -23,10 +32,6 @@ static void tmrUpdate(VB *sim, uint16_t value) {
|
||||
/* Process component */
|
||||
static void tmrEmulate(VB *sim, uint32_t clocks) {
|
||||
|
||||
/* Timer is disabled */
|
||||
if (!sim->tmr.t_enb)
|
||||
return;
|
||||
|
||||
/* Process all clocks */
|
||||
for (;;) {
|
||||
|
||||
@@ -38,15 +43,22 @@ static void tmrEmulate(VB *sim, uint32_t clocks) {
|
||||
}
|
||||
|
||||
/* Advance forward the component's number of clocks */
|
||||
clocks -= sim->tmr.clocks;
|
||||
sim->tmr.until -= sim->tmr.clocks;
|
||||
sim->tmr.clocks = sim->tmr.t_clk_sel ? 400 : 2000;
|
||||
clocks -= sim->tmr.clocks;
|
||||
sim->tmr.until -= sim->tmr.clocks;
|
||||
sim->tmr.clocks = 400;
|
||||
sim->tmr.tick20 += sim->tmr.tick20 == 4 ? -4 : 1;
|
||||
|
||||
/* Do not decrement counter */
|
||||
if (
|
||||
!sim->tmr.t_enb ||
|
||||
(!sim->tmr.t_clk_sel && sim->tmr.tick20 != 0)
|
||||
) continue;
|
||||
|
||||
/* Advance to the next counter value */
|
||||
tmrUpdate(sim, sim->tmr.counter == 0 ?
|
||||
sim->tmr.reload : sim->tmr.counter - 1);
|
||||
if (sim->tmr.counter == 0)
|
||||
sim->tmr.until = sim->tmr.clocks * ((uint32_t)sim->tmr.reload + 1);
|
||||
sim->tmr.until = tmrGetUntil(sim);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -71,8 +83,10 @@ static void tmrReset(VB *sim) {
|
||||
sim->tmr.z_stat = 0;
|
||||
|
||||
/* Other */
|
||||
sim->tmr.clocks = 400;
|
||||
sim->tmr.counter = 0xFFFF;
|
||||
sim->tmr.reload = 0x0000;
|
||||
sim->tmr.tick20 = 0;
|
||||
}
|
||||
|
||||
/* Determine how many clocks are guaranteed to process */
|
||||
@@ -88,14 +102,27 @@ static void tmrWriteControl(VB *sim, uint8_t value) {
|
||||
if (
|
||||
(value & 0x04) && /* Z-Stat-Clr */
|
||||
(
|
||||
sim->tmr.counter != 0 ||
|
||||
!sim->tmr.t_enb
|
||||
!sim->tmr.t_enb ||
|
||||
(
|
||||
sim->tmr.counter != 0 &&
|
||||
!(value & 0x01) /* T-Enb */
|
||||
)
|
||||
)
|
||||
) {
|
||||
sim->tmr.z_stat = sim->tmr.counter != 0;
|
||||
sim->cpu.irq &= ~0x0002;
|
||||
}
|
||||
|
||||
/* Hardware bug: decrement on switch to 20us mode */
|
||||
if (
|
||||
!sim->tmr.t_clk_sel &&
|
||||
(value & 0x10) && /* T-Clk-Sel */
|
||||
sim->tmr.tick20 != 0
|
||||
) {
|
||||
tmrUpdate(sim, sim->tmr.counter == 0 ?
|
||||
sim->tmr.reload : sim->tmr.counter - 1);
|
||||
}
|
||||
|
||||
/* Parse fields */
|
||||
sim->tmr.t_clk_sel = value >> 4 & 1;
|
||||
sim->tmr.tim_z_int = value >> 3 & 1;
|
||||
@@ -105,10 +132,8 @@ static void tmrWriteControl(VB *sim, uint8_t value) {
|
||||
if (!sim->tmr.tim_z_int)
|
||||
sim->cpu.irq &= ~0x0002;
|
||||
|
||||
/* Configure countdowns */
|
||||
sim->tmr.clocks = sim->tmr.t_clk_sel ? 400 : 2000;
|
||||
sim->tmr.until = sim->tmr.clocks * (sim->tmr.counter == 0 ?
|
||||
(uint32_t) sim->tmr.reload + 1 : sim->tmr.counter);
|
||||
/* Configure state */
|
||||
sim->tmr.until = tmrGetUntil(sim);
|
||||
|
||||
/* TODO: Will Z-Stat raise an interrupt when Tim-Z-Int is set? */
|
||||
}
|
||||
@@ -117,12 +142,14 @@ static void tmrWriteControl(VB *sim, uint8_t value) {
|
||||
static void tmrWriteHigh(VB *sim, uint8_t value) {
|
||||
sim->tmr.reload = (uint16_t) value << 8 | (sim->tmr.reload & 0x00FF);
|
||||
tmrUpdate(sim, sim->tmr.reload);
|
||||
sim->tmr.until = tmrGetUntil(sim);
|
||||
}
|
||||
|
||||
/* Write to the low data register */
|
||||
static void tmrWriteLow(VB *sim, uint8_t value) {
|
||||
sim->tmr.reload = (sim->tmr.reload & 0xFF00) | value;
|
||||
tmrUpdate(sim, sim->tmr.reload);
|
||||
sim->tmr.until = tmrGetUntil(sim);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,8 +8,11 @@
|
||||
|
||||
/*********************************** Types ***********************************/
|
||||
|
||||
/* Output image */
|
||||
typedef uint8_t Pixels[2][384*224];
|
||||
/* VIP BG map cell */
|
||||
typedef struct {
|
||||
uint8_t *palette; /* Points to a VB.vip.gplt */
|
||||
uint8_t *pixels; /* Points to a VB.vip.characters */
|
||||
} Cell;
|
||||
|
||||
/* VSU channel */
|
||||
typedef struct {
|
||||
@@ -64,9 +67,58 @@ typedef struct {
|
||||
} wave;
|
||||
|
||||
/* Other state */
|
||||
uint32_t clocks; /* Clocks until next sample */
|
||||
uint32_t clocks; /* Clocks until next wave or noise sample */
|
||||
uint8_t freqmod; /* Frequency modifications are active */
|
||||
uint32_t until; /* Clocks until channel component update */
|
||||
} Channel;
|
||||
|
||||
/* VIP character (hflp << 1 | vflp) */
|
||||
typedef uint8_t Character[4][64];
|
||||
|
||||
/* VIP object */
|
||||
typedef struct {
|
||||
Cell cell; /* BG map-like attributes */
|
||||
int16_t jp; /* Parallax */
|
||||
int16_t jx; /* Screen base X */
|
||||
int16_t jy; /* Screen Y */
|
||||
uint8_t lron; /* Visible in left and right images */
|
||||
} Object;
|
||||
|
||||
/* Output image */
|
||||
typedef uint8_t Pixels[2][384*224];
|
||||
|
||||
/* VIP world */
|
||||
typedef struct {
|
||||
|
||||
/* Attributes */
|
||||
uint8_t bgm; /* Mode */
|
||||
uint8_t end; /* Control world */
|
||||
int16_t gp; /* World parallax */
|
||||
int16_t gx; /* World base X */
|
||||
int16_t gy; /* World Y */
|
||||
int16_t mx; /* Scroll base X */
|
||||
int16_t mp; /* Scroll parallax */
|
||||
int16_t my; /* Scroll Y */
|
||||
uint8_t over; /* Use overplane */
|
||||
Cell *overplane; /* Overplane cell */
|
||||
|
||||
/* Non-attributes */
|
||||
Cell *bg[64]; /* Background arrangement */
|
||||
int32_t bgHeight; /* Height of background in pixels */
|
||||
uint32_t bgMaskX; /* Horizontal background mask */
|
||||
uint32_t bgMaskY; /* Vertical background mask */
|
||||
uint32_t bgShift; /* Bits to shift when selecting a BG map */
|
||||
int32_t bgWidth; /* Width of background in pixels */
|
||||
uint32_t hAffine; /* H for affine mode */
|
||||
uint32_t hNaffine; /* H for not affine mode */
|
||||
uint32_t height; /* Height of world in pixels */
|
||||
uint8_t lron; /* Visible in left and right images */
|
||||
uint32_t paramBase; /* H-bias and affine parameter address */
|
||||
uint32_t wAffine; /* W for affine mode */
|
||||
uint32_t wNaffine; /* W for not affine mode */
|
||||
uint32_t width; /* Width of world in pixels */
|
||||
} World;
|
||||
|
||||
/* Simulation state */
|
||||
struct VB {
|
||||
|
||||
@@ -199,6 +251,7 @@ struct VB {
|
||||
uint32_t clocks; /* Master clocks to wait */
|
||||
uint16_t counter; /* Current counter value */
|
||||
uint16_t reload; /* Reload counter value */
|
||||
uint8_t tick20; /* Current 20-microsecond tick */
|
||||
uint32_t until; /* Clocks until interrupt condition */
|
||||
} tmr;
|
||||
|
||||
@@ -259,6 +312,7 @@ struct VB {
|
||||
int frame; /* FRMCYC counter */
|
||||
int32_t halfword; /* Current output halfword offset */
|
||||
int step; /* Processing phase */
|
||||
uint8_t toggle; /* Switch frame buffers next frame */
|
||||
uint32_t until; /* Clocks until interrupt condition */
|
||||
} xp;
|
||||
|
||||
@@ -273,12 +327,17 @@ struct VB {
|
||||
uint16_t spt[4]; /* Object control */
|
||||
|
||||
/* Rendering shadow memory */
|
||||
uint8_t buffer; /* Output buffer */
|
||||
uint16_t halfwords[384*28]; /* Output timing by 1x8 halfword */
|
||||
Pixels output[2]; /* Output images, row-major */
|
||||
Pixels shadow; /* Drawing shadow image, column-major */
|
||||
|
||||
/* Other state */
|
||||
uint8_t ram[0x40000]; /* Video memory */
|
||||
Cell cells[0x10000]; /* Pre-computed BG map attributes */
|
||||
Character characters[2048]; /* Pre-computed character pixels */
|
||||
Object objects[1024]; /* Pre-computed object attributes */
|
||||
uint8_t ram[0x40000]; /* Video memory */
|
||||
World worlds[32]; /* Pre-computed world attributes */
|
||||
} vip;
|
||||
|
||||
/* VSU */
|
||||
@@ -575,7 +634,7 @@ VBAPI void vbGetPixels(VB *sim, void *left, int leftStrideX, int leftStrideY,
|
||||
continue;
|
||||
|
||||
/* Transfer pixels to the destination */
|
||||
src = sim->vip.output[sim->vip.dp.buffer ^ 1][i];
|
||||
src = sim->vip.output[sim->vip.buffer][i];
|
||||
for (y = 0; y < 224; y++, dest += yStride)
|
||||
for (x = offset = 0; x < 384; x++, offset += xStride)
|
||||
dest[offset] = *src++;
|
||||
@@ -643,6 +702,7 @@ VBAPI vbOnWrite vbGetWriteCallback(VB *sim) {
|
||||
VBAPI VB* vbInit(VB *sim) {
|
||||
sim->cart.ram = NULL;
|
||||
sim->cart.rom = NULL;
|
||||
sim->ph.enabled = 0;
|
||||
sim->vsu.out.samples = NULL;
|
||||
sim->onExecute = NULL;
|
||||
sim->onFetch = NULL;
|
||||
@@ -652,7 +712,7 @@ VBAPI VB* vbInit(VB *sim) {
|
||||
sim->onSamples = NULL;
|
||||
sim->onWrite = NULL;
|
||||
sim->peer = NULL;
|
||||
sim->ph.enabled = 0;
|
||||
sim->tag = NULL;
|
||||
vbReset(sim);
|
||||
return sim;
|
||||
}
|
||||
@@ -716,28 +776,28 @@ VBAPI int vbSetCartROM(VB *sim, void *rom, uint32_t size) {
|
||||
/* Specify a new exception callback handler */
|
||||
VBAPI vbOnException vbSetExceptionCallback(VB *sim, vbOnException callback) {
|
||||
vbOnException prev = sim->onException;
|
||||
sim->onException = callback;
|
||||
sim->onException = callback;
|
||||
return prev;
|
||||
}
|
||||
|
||||
/* Specify a new execute callback handler */
|
||||
VBAPI vbOnExecute vbSetExecuteCallback(VB *sim, vbOnExecute callback) {
|
||||
vbOnExecute prev = sim->onExecute;
|
||||
sim->onExecute = callback;
|
||||
sim->onExecute = callback;
|
||||
return prev;
|
||||
}
|
||||
|
||||
/* Specify a new fetch callback handler */
|
||||
VBAPI vbOnFetch vbSetFetchCallback(VB *sim, vbOnFetch callback) {
|
||||
vbOnFetch prev = sim->onFetch;
|
||||
sim->onFetch = callback;
|
||||
sim->onFetch = callback;
|
||||
return prev;
|
||||
}
|
||||
|
||||
/* Specify a new frame callback handler */
|
||||
VBAPI vbOnFrame vbSetFrameCallback(VB *sim, vbOnFrame callback) {
|
||||
vbOnFrame prev = sim->onFrame;
|
||||
sim->onFrame = callback;
|
||||
sim->onFrame = callback;
|
||||
return prev;
|
||||
}
|
||||
|
||||
@@ -749,7 +809,7 @@ VBAPI uint16_t vbSetKeys(VB *sim, uint16_t keys) {
|
||||
/* Specify a new link callback handler */
|
||||
VBAPI vbOnLink vbSetLinkCallback(VB *sim, vbOnLink callback) {
|
||||
vbOnLink prev = sim->onLink;
|
||||
sim->onLink = callback;
|
||||
sim->onLink = callback;
|
||||
return prev;
|
||||
}
|
||||
|
||||
@@ -774,6 +834,8 @@ VBAPI int vbSetOption(VB *sim, int key, int value) {
|
||||
VBAPI void vbSetPeer(VB *sim, VB *peer) {
|
||||
if (sim->peer == peer)
|
||||
return;
|
||||
if (sim->peer != NULL)
|
||||
sim->peer->peer = NULL;
|
||||
sim->peer = peer;
|
||||
if (peer == NULL)
|
||||
return;
|
||||
@@ -784,6 +846,7 @@ VBAPI void vbSetPeer(VB *sim, VB *peer) {
|
||||
|
||||
/* Specify a new value for the program counter */
|
||||
VBAPI uint32_t vbSetProgramCounter(VB *sim, uint32_t value) {
|
||||
sim->cpu.clocks = 0;
|
||||
sim->cpu.operation = CPU_FETCH;
|
||||
sim->cpu.pc = sim->cpu.nextPC = value & 0xFFFFFFFE;
|
||||
sim->cpu.step = 0;
|
||||
@@ -798,7 +861,7 @@ VBAPI int32_t vbSetProgramRegister(VB *sim, unsigned index, int32_t value) {
|
||||
/* Specify a new read callback handler */
|
||||
VBAPI vbOnRead vbSetReadCallback(VB *sim, vbOnRead callback) {
|
||||
vbOnRead prev = sim->onRead;
|
||||
sim->onRead = callback;
|
||||
sim->onRead = callback;
|
||||
return prev;
|
||||
}
|
||||
|
||||
@@ -829,7 +892,7 @@ VBAPI uint32_t vbSetSystemRegister(VB *sim, unsigned index, uint32_t value) {
|
||||
/* Specify a new write callback handler */
|
||||
VBAPI vbOnWrite vbSetWriteCallback(VB *sim, vbOnWrite callback) {
|
||||
vbOnWrite prev = sim->onWrite;
|
||||
sim->onWrite = callback;
|
||||
sim->onWrite = callback;
|
||||
return prev;
|
||||
}
|
||||
|
||||
@@ -841,7 +904,7 @@ VBAPI size_t vbSizeOf() {
|
||||
/* Specify a simulation's userdata pointer */
|
||||
VBAPI void* vbSetUserData(VB *sim, void *tag) {
|
||||
void *prev = sim->tag;
|
||||
sim->tag = tag;
|
||||
sim->tag = tag;
|
||||
return prev;
|
||||
}
|
||||
|
||||
|
||||
@@ -126,7 +126,6 @@ typedef int (*vbOnWrite )(VB *sim, uint32_t address, int type, int32_t *valu
|
||||
|
||||
VBAPI int vbEmulate (VB *sim, uint32_t *clocks);
|
||||
VBAPI int vbEmulateEx (VB **sims, unsigned count, uint32_t *clocks);
|
||||
VBAPI void* vbGetCallback (VB *sim, int id);
|
||||
VBAPI void* vbGetCartRAM (VB *sim, uint32_t *size);
|
||||
VBAPI void* vbGetCartROM (VB *sim, uint32_t *size);
|
||||
VBAPI vbOnException vbGetExceptionCallback(VB *sim);
|
||||
|
||||
+595
-317
File diff suppressed because it is too large
Load Diff
+96
-89
@@ -74,100 +74,57 @@ static void vsuNextFreqMod(VB *sim, Channel *chan) {
|
||||
}
|
||||
|
||||
/* Process one channel */
|
||||
static void vsuEmulateChannel(VB *sim, int index, uint32_t clocks) {
|
||||
uint32_t bit; /* Pseudorandom bit */
|
||||
Channel *chan; /* Channel handle */
|
||||
int freqmod; /* Frequency modifications enabled */
|
||||
uint32_t until; /* Clocks to process sub-channel components */
|
||||
static void vsuEmulateChannel(VB *sim, Channel *chan) {
|
||||
uint32_t bit; /* Pseudorandom bit */
|
||||
|
||||
/* Select channel */
|
||||
chan = &sim->vsu.channels[index];
|
||||
|
||||
/* Channel is disabled */
|
||||
if (!chan->int_.enb)
|
||||
/* Automatic shutoff */
|
||||
if (chan->int_.auto_ && chan->int_.clocks == 0) {
|
||||
chan->int_.enb = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Process all clocks */
|
||||
do {
|
||||
/* Next input sample */
|
||||
if (chan->clocks == 0) {
|
||||
|
||||
/* Frequency modifications are active */
|
||||
freqmod =
|
||||
index == 4 && /* Channel 5 */
|
||||
sim->vsu.freqmod.enb && /* Modifications enabled */
|
||||
sim->vsu.freqmod.interval != 0 /* Modifications valid */
|
||||
;
|
||||
/* Wave */
|
||||
if (chan != &sim->vsu.channels[5]) {
|
||||
chan->clocks = 4 * (2048 - (uint32_t) chan->freq.current);
|
||||
chan->wave.sample = (chan->wave.sample + 1) & 31;
|
||||
}
|
||||
|
||||
/* Clocks until next state change */
|
||||
until = clocks;
|
||||
if (chan->clocks < until)
|
||||
until = chan->clocks;
|
||||
if (chan->env.enb && chan->env.clocks < until)
|
||||
until = chan->env.clocks;
|
||||
if (chan->int_.auto_ && chan->int_.clocks < until)
|
||||
until = chan->int_.clocks;
|
||||
if (freqmod && sim->vsu.freqmod.clocks < until)
|
||||
until = sim->vsu.freqmod.clocks;
|
||||
/* Noise */
|
||||
else {
|
||||
chan->clocks = 40 * (2048 - (uint32_t) chan->freq.current);
|
||||
bit = ((
|
||||
sim->vsu.noise.register_ >> NOISE_TAPS[sim->vsu.noise.tap]^
|
||||
sim->vsu.noise.register_ >> 7
|
||||
) & 1) ^ 1;
|
||||
sim->vsu.noise.register_ = bit |
|
||||
(sim->vsu.noise.register_ << 1 & 0x7FFE);
|
||||
}
|
||||
|
||||
/* Manage clocks */
|
||||
clocks -= until;
|
||||
chan->clocks -= until;
|
||||
if (chan->env.enb)
|
||||
chan->env.clocks -= until;
|
||||
if (chan->int_.auto_)
|
||||
chan->int_.clocks -= until;
|
||||
if (freqmod)
|
||||
sim->vsu.freqmod.clocks -= until;
|
||||
}
|
||||
|
||||
/* Automatic shutoff */
|
||||
if (chan->int_.auto_ && chan->int_.clocks == 0) {
|
||||
chan->int_.enb = 0;
|
||||
/* Envelope modification */
|
||||
if (chan->env.enb && chan->env.clocks == 0) {
|
||||
if (chan->env.dir == 0 && chan->env.value != 0)
|
||||
chan->env.value--;
|
||||
else if (chan->env.dir == 1 && chan->env.value != 15)
|
||||
chan->env.value++;
|
||||
else if (chan->env.rep)
|
||||
chan->env.value = chan->env.reload;
|
||||
chan->env.clocks = ((uint32_t) chan->env.interval + 1) * 307220;
|
||||
}
|
||||
|
||||
/* Frequency modification */
|
||||
if (chan->freqmod && sim->vsu.freqmod.clocks == 0) {
|
||||
chan->freq.current = sim->vsu.freqmod.next;
|
||||
vsuNextFreqMod(sim, chan);
|
||||
if (!chan->int_.enb)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Next sample */
|
||||
if (chan->clocks == 0) {
|
||||
|
||||
/* Wave */
|
||||
if (index != 5) {
|
||||
chan->clocks = 4 * (2048 - (uint32_t) chan->freq.current);
|
||||
chan->wave.sample = (chan->wave.sample + 1) & 31;
|
||||
}
|
||||
|
||||
/* Noise */
|
||||
else {
|
||||
chan->clocks = 40 * (2048 - (uint32_t) chan->freq.current);
|
||||
bit = ((
|
||||
sim->vsu.noise.register_ >> NOISE_TAPS[sim->vsu.noise.tap]^
|
||||
sim->vsu.noise.register_ >> 7
|
||||
) & 1) ^ 1;
|
||||
sim->vsu.noise.register_ = bit |
|
||||
(sim->vsu.noise.register_ << 1 & 0x7FFE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Envelope modification */
|
||||
if (chan->env.enb && chan->env.clocks == 0) {
|
||||
if (chan->env.dir == 0 && chan->env.value != 0)
|
||||
chan->env.value--;
|
||||
else if (chan->env.dir == 1 && chan->env.value != 15)
|
||||
chan->env.value++;
|
||||
else if (chan->env.rep)
|
||||
chan->env.value = chan->env.reload;
|
||||
chan->env.clocks = ((uint32_t) chan->env.interval + 1) * 307220;
|
||||
}
|
||||
|
||||
/* Frequency modification */
|
||||
if (freqmod && sim->vsu.freqmod.clocks == 0) {
|
||||
chan->freq.current = sim->vsu.freqmod.next;
|
||||
vsuNextFreqMod(sim, chan);
|
||||
if (!chan->int_.enb)
|
||||
return;
|
||||
sim->vsu.freqmod.clocks = (uint32_t) sim->vsu.freqmod.interval *
|
||||
(sim->vsu.freqmod.clk == 0 ? 19200 : 153600);
|
||||
}
|
||||
|
||||
} while (clocks != 0);
|
||||
sim->vsu.freqmod.clocks = (uint32_t) sim->vsu.freqmod.interval *
|
||||
(sim->vsu.freqmod.clk == 0 ? 19200 : 153600);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -230,6 +187,8 @@ static void vsuWriteEV1(VB *sim, int index, uint8_t value) {
|
||||
sim->vsu.freqmod.func = value >> 4 & 1;
|
||||
sim->vsu.freqmod.rep = value >> 5 & 1;
|
||||
vsuNextFreqMod(sim, chan);
|
||||
chan->freqmod =
|
||||
sim->vsu.freqmod.enb && sim->vsu.freqmod.interval != 0;
|
||||
break;
|
||||
|
||||
case 5: /* Channel 6 */
|
||||
@@ -313,6 +272,8 @@ static void vsuWriteSWP(VB *sim, uint8_t value) {
|
||||
(sim->vsu.freqmod.clk == 0 ? 19200 : 153600);
|
||||
if (clocks < sim->vsu.freqmod.clocks)
|
||||
sim->vsu.freqmod.clocks = clocks;
|
||||
sim->vsu.channels[4].freqmod =
|
||||
sim->vsu.freqmod.enb && sim->vsu.freqmod.interval != 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -321,6 +282,8 @@ static void vsuWriteSWP(VB *sim, uint8_t value) {
|
||||
|
||||
/* Process component */
|
||||
static void vsuEmulate(VB *sim, uint32_t clocks) {
|
||||
Channel *chan; /* Input channel */
|
||||
uint32_t chantil; /* Clocks until next channel state update */
|
||||
float i0; /* Current analog input sample */
|
||||
float o0; /* Current analog output sample */
|
||||
uint16_t output[2]; /* Digital output samples */
|
||||
@@ -340,12 +303,54 @@ static void vsuEmulate(VB *sim, uint32_t clocks) {
|
||||
sim->vsu.clocks -= until;
|
||||
|
||||
/* Process all channels */
|
||||
for (x = 0; x < 6; x++)
|
||||
vsuEmulateChannel(sim, x, until);
|
||||
for (x = 0; x < 6; x++) {
|
||||
chan = &sim->vsu.channels[x];
|
||||
chantil = until;
|
||||
|
||||
/* Process all clocks */
|
||||
while (chan->int_.enb && chantil != 0) {
|
||||
|
||||
/* Determine when the next state change will occur */
|
||||
if (chan->until == 0) {
|
||||
|
||||
/* Clocks until next state change */
|
||||
chan->until = chan->clocks;
|
||||
if (chan->env.enb && chan->env.clocks < chan->until)
|
||||
chan->until = chan->env.clocks;
|
||||
if (chan->int_.auto_ && chan->int_.clocks < chan->until)
|
||||
chan->until = chan->int_.clocks;
|
||||
if (chan->freqmod && sim->vsu.freqmod.clocks < chan->until)
|
||||
chan->until = sim->vsu.freqmod.clocks;
|
||||
|
||||
/* Manage clocks */
|
||||
chan->clocks -= chan->until;
|
||||
if (chan->env.enb)
|
||||
chan->env.clocks -= chan->until;
|
||||
if (chan->int_.auto_)
|
||||
chan->int_.clocks -= chan->until;
|
||||
if (chan->freqmod)
|
||||
sim->vsu.freqmod.clocks -= chan->until;
|
||||
}
|
||||
|
||||
/* Manage clocks */
|
||||
if (chan->until > chantil) {
|
||||
chan->until -= chantil;
|
||||
chantil = 0;
|
||||
} else {
|
||||
chantil -= chan->until;
|
||||
chan->until = 0;
|
||||
}
|
||||
|
||||
/* Update channel state */
|
||||
if (chan->until == 0)
|
||||
vsuEmulateChannel(sim, chan);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Wait for the current sample to finish */
|
||||
if (sim->vsu.clocks != 0)
|
||||
continue;
|
||||
return;
|
||||
|
||||
/* Compute the output sample */
|
||||
output[0] = output[1] = 0;
|
||||
@@ -416,6 +421,8 @@ static void vsuReset(VB *sim) {
|
||||
for (x = 0; x < 6; x++) {
|
||||
chan = &sim->vsu.channels[x];
|
||||
chan->clocks = 0;
|
||||
chan->freqmod = 0;
|
||||
chan->until = 0;
|
||||
chan->env.clocks = 0;
|
||||
chan->env.enb = 0;
|
||||
chan->env.dir = 0;
|
||||
|
||||
+22
-16
@@ -1,4 +1,4 @@
|
||||
/* This file is included into vb.c and cannot be compiled on its own. */
|
||||
/* This file is included into vbu.c and cannot be compiled on its own. */
|
||||
#ifdef VBUAPI
|
||||
|
||||
|
||||
@@ -253,18 +253,24 @@ static void dasmOpDisp26(char*dest, VBU_DasmConfig*config, VBU_DasmLine*line) {
|
||||
}
|
||||
|
||||
/* Format a 5-bit sign-extended immediate operand */
|
||||
static void dasmOpImm5S(char *dest, VBU_DasmLine *line) {
|
||||
static void dasmOpImm5S(char *dest, VBU_DasmConfig*config, VBU_DasmLine *line){
|
||||
if (config->immediateNotation == VBU_NUMBER)
|
||||
*dest++ = '#';
|
||||
sprintf(dest, "%d", SignExtend(line->code[0], 5));
|
||||
}
|
||||
|
||||
/* Format a 5-bit zero-filled immediate operand */
|
||||
static void dasmOpImm5U(char *dest, VBU_DasmLine *line) {
|
||||
static void dasmOpImm5U(char *dest, VBU_DasmConfig*config, VBU_DasmLine *line){
|
||||
if (config->immediateNotation == VBU_NUMBER)
|
||||
*dest++ = '#';
|
||||
sprintf(dest, "%d", line->code[0] & 31);
|
||||
}
|
||||
|
||||
/* Format a 16-bit sign-extended immediate operand */
|
||||
static void dasmOpImm16S(char*dest, VBU_DasmConfig*config, VBU_DasmLine*line) {
|
||||
int32_t imm = (int16_t) ((int16_t) line->code[3] << 8 | line->code[2]);
|
||||
int32_t imm = (int16_t) ((int16_t) line->code[3] << 8 | line->code[2]);
|
||||
if (config->immediateNotation == VBU_NUMBER)
|
||||
*dest++ = '#';
|
||||
if (imm >= -256 && imm <= 256) {
|
||||
sprintf(dest, "%d", imm);
|
||||
return;
|
||||
@@ -279,6 +285,8 @@ static void dasmOpImm16S(char*dest, VBU_DasmConfig*config, VBU_DasmLine*line) {
|
||||
/* Format a 16-bit zero-filled immediate operand */
|
||||
static void dasmOpImm16U(char*dest, VBU_DasmConfig*config, VBU_DasmLine*line) {
|
||||
uint16_t imm = (uint16_t) line->code[3] << 8 | line->code[2];
|
||||
if (config->immediateNotation == VBU_NUMBER)
|
||||
*dest++ = '#';
|
||||
dasmToHex(dest, config, 4, imm);
|
||||
}
|
||||
|
||||
@@ -441,12 +449,6 @@ static VBU_DasmLine* dasmGrow(
|
||||
return *lines == NULL ? NULL : &(*lines)[index];
|
||||
}
|
||||
|
||||
/* Determine the size of an instruction */
|
||||
static uint32_t dasmInstSize(VB *sim, uint32_t address) {
|
||||
unsigned opcode = vbRead(sim, address, VB_U16) >> 10 & 63;
|
||||
return opcode < 0x20 || opcode == 0x32 || opcode == 0x36 ? 2 : 4;
|
||||
}
|
||||
|
||||
/* Format an operand */
|
||||
static void dasmOperand(char *dest, VBU_DasmConfig *config,
|
||||
VBU_DasmLine *line, uint8_t type) {
|
||||
@@ -454,8 +456,8 @@ static void dasmOperand(char *dest, VBU_DasmConfig *config,
|
||||
case DASM_BCOND : dasmOpBCOND (dest, config, line); break;
|
||||
case DASM_DISP9 : dasmOpDisp9 (dest, config, line); break;
|
||||
case DASM_DISP26: dasmOpDisp26(dest, config, line); break;
|
||||
case DASM_IMM5S : dasmOpImm5S (dest, line); break;
|
||||
case DASM_IMM5U : dasmOpImm5U (dest, line); break;
|
||||
case DASM_IMM5S : dasmOpImm5S (dest, config, line); break;
|
||||
case DASM_IMM5U : dasmOpImm5U (dest, config, line); break;
|
||||
case DASM_IMM16S: dasmOpImm16S(dest, config, line); break;
|
||||
case DASM_IMM16U: dasmOpImm16U(dest, config, line); break;
|
||||
case DASM_JMP : dasmOpJMP (dest, config, line); break;
|
||||
@@ -507,10 +509,12 @@ static int dasmLine(VB *sim, uint32_t *address, uint32_t pc,
|
||||
/* Process non-text members */
|
||||
line = &(*lines)[index];
|
||||
line->address = *address;
|
||||
line->codeLength = dasmInstSize(sim, *address);
|
||||
line->codeLength = vbuCodeSize(sim, *address);
|
||||
line->isPC = *address == pc;
|
||||
for (x = 0; x < line->codeLength; x++)
|
||||
line->code[x] = vbRead(sim, *address + x, VB_U8);
|
||||
|
||||
/* Advance to the next instruction or PC, whichever is sooner */
|
||||
*address += pc != *address && pc - *address < line->codeLength ?
|
||||
pc - *address : line->codeLength;
|
||||
|
||||
@@ -652,9 +656,11 @@ static VBU_DasmLine* dasmDisassemble(VB *sim, uint32_t address,
|
||||
}
|
||||
|
||||
/* Check if the instruction contains the reference address */
|
||||
size = dasmInstSize(sim, addr);
|
||||
size = vbuCodeSize(sim, addr);
|
||||
if (address - addr < size)
|
||||
break;
|
||||
|
||||
/* Advance to the next instruction or PC, whichever is sooner */
|
||||
addr += addr != pc && pc - addr < size ? pc - addr : size;
|
||||
}
|
||||
|
||||
@@ -666,7 +672,7 @@ static VBU_DasmLine* dasmDisassemble(VB *sim, uint32_t address,
|
||||
|
||||
/* Keep decoding until the first line of output */
|
||||
else for (; line < 0; line++)
|
||||
addr += dasmInstSize(sim, addr);
|
||||
addr += vbuCodeSize(sim, addr);
|
||||
|
||||
/* Working variables */
|
||||
size = length * sizeof (VBU_DasmLine);
|
||||
@@ -680,7 +686,7 @@ static VBU_DasmLine* dasmDisassemble(VB *sim, uint32_t address,
|
||||
if (dasmLine(sim, &addr, pc, config, &lines, &size, &offset, x))
|
||||
goto catch;
|
||||
}
|
||||
return lines;
|
||||
return VBU_REALLOC(lines, offset);
|
||||
|
||||
/* Exception handler */
|
||||
catch:
|
||||
|
||||
@@ -38,6 +38,12 @@ static int32_t SignExtend(int32_t value, int32_t bits) {
|
||||
|
||||
/******************************* API Commands ********************************/
|
||||
|
||||
/* Determine the size in bytes of an instruction */
|
||||
VBUAPI int vbuCodeSize(VB *sim, uint32_t address) {
|
||||
int opcode = vbRead(sim, address, VB_U16) >> 10 & 63;
|
||||
return opcode < 0x20 || opcode == 0x32 || opcode == 0x36 ? 2 : 4;
|
||||
}
|
||||
|
||||
/* Initialize disassembler options with default settings */
|
||||
VBUAPI VBU_DasmConfig* vbuDasmInit(VBU_DasmConfig *config) {
|
||||
config->bcondNotation = VBU_JOINED;
|
||||
@@ -47,6 +53,7 @@ VBUAPI VBU_DasmConfig* vbuDasmInit(VBU_DasmConfig *config) {
|
||||
config->conditionNotation = VBU_NAMES;
|
||||
config->hexCase = VBU_UPPER;
|
||||
config->hexNotation = VBU_0X;
|
||||
config->immediateNotation = VBU_NONE;
|
||||
config->memoryNotation = VBU_OUTSIDE;
|
||||
config->mnemonicCase = VBU_UPPER;
|
||||
config->operandOrder = VBU_DEST_LAST;
|
||||
|
||||
@@ -29,6 +29,8 @@ extern "C" {
|
||||
#define VBU_L 0
|
||||
#define VBU_LOWER 1
|
||||
#define VBU_NAMES 1
|
||||
#define VBU_NONE 0
|
||||
#define VBU_NUMBER 1
|
||||
#define VBU_NUMBERS 0
|
||||
#define VBU_OUTSIDE 0
|
||||
#define VBU_SPLIT 1
|
||||
@@ -48,6 +50,7 @@ typedef struct { /* Defaults listed first */
|
||||
uint8_t conditionNotation; /* NAMES, NUMBERS */
|
||||
uint8_t hexCase; /* UPPER, LOWER */
|
||||
uint8_t hexNotation; /* 0X, H, DOLLAR */
|
||||
uint8_t immediateNotation; /* NONE, NUMBER */
|
||||
uint8_t memoryNotation; /* OUTSIDE, INSIDE */
|
||||
uint8_t mnemonicCase; /* UPPER, LOWER */
|
||||
uint8_t operandOrder; /* DEST_LAST, DEST_FIRST */
|
||||
@@ -82,6 +85,7 @@ typedef struct {
|
||||
|
||||
/******************************* API Commands ********************************/
|
||||
|
||||
VBUAPI int vbuCodeSize (VB *sim, uint32_t address);
|
||||
VBUAPI VBU_DasmConfig* vbuDasmInit (VBU_DasmConfig *config);
|
||||
VBUAPI VBU_DasmLine* vbuDisassemble(VB *sim, uint32_t address, VBU_DasmConfig *config, unsigned length, int line);
|
||||
|
||||
|
||||
@@ -61,6 +61,8 @@ let Constants = {
|
||||
L : 0,
|
||||
LOWER : 1,
|
||||
NAMES : 1,
|
||||
NONE : 0,
|
||||
NUMBER : 1,
|
||||
NUMBERS : 0,
|
||||
OUTSIDE : 0,
|
||||
SPLIT : 1,
|
||||
|
||||
+15
-7
@@ -87,11 +87,8 @@ new class Core {
|
||||
this.sims.set(sim.pointer, sim);
|
||||
|
||||
// Video
|
||||
sim.pixels = this.#noalloc(
|
||||
this.GetExtPixels(sim.pointer),
|
||||
384*224*4, sim, "pixels", Uint8ClampedArray
|
||||
);
|
||||
sim.image = new ImageData(sim.pixels, 384, 224);
|
||||
sim.pixels = this.#getPixels(sim);
|
||||
sim.image = new ImageData(sim.pixels, 384, 224);
|
||||
|
||||
// Audio
|
||||
sim.samples = this.#noalloc(
|
||||
@@ -128,6 +125,7 @@ new class Core {
|
||||
message.config.conditionNotation,
|
||||
message.config.hexCase,
|
||||
message.config.hexNotation,
|
||||
message.config.immediateNotation,
|
||||
message.config.memoryNotation,
|
||||
message.config.mnemonicCase,
|
||||
message.config.operandOrder,
|
||||
@@ -363,8 +361,10 @@ new class Core {
|
||||
this.mallocs.set(buffer.pointer, buffer);
|
||||
this.#updateTarget(buffer);
|
||||
}
|
||||
for (let sim of this.sims)
|
||||
sim.image = new ImageData(sim.pixels, 384, 224);
|
||||
for (let sim of this.sims.values()) {
|
||||
sim.pixels = this.#getPixels(sim);
|
||||
sim.image = new ImageData(sim.pixels, 384, 224);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -435,6 +435,14 @@ new class Core {
|
||||
this.Realloc(buffer.pointer, 0);
|
||||
}
|
||||
|
||||
// Register a sim's pixel buffer
|
||||
#getPixels(sim) {
|
||||
return this.#noalloc(
|
||||
this.GetExtPixels(sim.pointer),
|
||||
384*224*4, sim, "pixels", Uint8ClampedArray
|
||||
);
|
||||
}
|
||||
|
||||
// Allocate memory in WebAssembly and register the buffer
|
||||
#malloc(count, target = null, assign = null, type = Uint8ClampedArray) {
|
||||
return this.#noalloc(
|
||||
|
||||
@@ -19,6 +19,7 @@ class DasmConfig {
|
||||
#conditionNotation;
|
||||
#hexCase;
|
||||
#hexNotation;
|
||||
#immediateNotation;
|
||||
#memoryNotation;
|
||||
#mnemonicCase;
|
||||
#operandOrder;
|
||||
@@ -40,6 +41,7 @@ class DasmConfig {
|
||||
this.#conditionNotation = Constants.VBU.NAMES;
|
||||
this.#hexCase = Constants.VBU.UPPER;
|
||||
this.#hexNotation = Constants.VBU["0X"];
|
||||
this.#immediateNotation = Constants.VBU.NONE;
|
||||
this.#memoryNotation = Constants.VBU.OUTSIDE;
|
||||
this.#mnemonicCase = Constants.VBU.UPPER;
|
||||
this.#operandOrder = Constants.VBU.DEST_LAST;
|
||||
@@ -125,6 +127,16 @@ class DasmConfig {
|
||||
this.#hexNotation = value;
|
||||
}
|
||||
|
||||
get immediateNotation() { return this.#immediateNotation; }
|
||||
set immediateNotation(value) {
|
||||
switch (value) {
|
||||
case Constants.VBU.NONE :
|
||||
case Constants.VBU.NUMBER: break;
|
||||
default: return;
|
||||
}
|
||||
this.#immediateNotation = value;
|
||||
}
|
||||
|
||||
get memoryNotation() { return this.#memoryNotation; }
|
||||
set memoryNotation(value) {
|
||||
switch (value) {
|
||||
@@ -407,6 +419,7 @@ class Sim extends HTMLElement {
|
||||
conditionNotation: config.conditionNotation,
|
||||
hexCase : config.hexCase,
|
||||
hexNotation : config.hexNotation,
|
||||
immediateNotation: config.immediateNotation,
|
||||
memoryNotation : config.memoryNotation,
|
||||
mnemonicCase : config.mnemonicCase,
|
||||
operandOrder : config.operandOrder,
|
||||
@@ -650,6 +663,8 @@ class VB {
|
||||
static get L () { return Constants.VBU.L ; }
|
||||
static get LOWER () { return Constants.VBU.LOWER ; }
|
||||
static get NAMES () { return Constants.VBU.NAMES ; }
|
||||
static get NONE () { return Constants.VBU.NONE ; }
|
||||
static get NUMBER () { return Constants.VBU.NUMBER ; }
|
||||
static get NUMBERS () { return Constants.VBU.NUMBERS ; }
|
||||
static get OUTSIDE () { return Constants.VBU.OUTSIDE ; }
|
||||
static get RELATIVE () { return Constants.VBU.RELATIVE ; }
|
||||
|
||||
+4
-3
@@ -108,9 +108,9 @@ EMSCRIPTEN_KEEPALIVE void* CreateSim() {
|
||||
// Disassemble from a simulation
|
||||
EMSCRIPTEN_KEEPALIVE void* Disassemble(
|
||||
int bcondNotation, int conditionCase, int conditionCL, int conditionEZ,
|
||||
int conditionNotation, int hexCase, int hexNotation, int memoryNotation,
|
||||
int mnemonicCase, int operandOrder, int programCase, int programNotation,
|
||||
int setfNotation, int systemCase, int systemNotation,
|
||||
int conditionNotation, int hexCase, int hexNotation, int immediateNotation,
|
||||
int memoryNotation, int mnemonicCase, int operandOrder, int programCase,
|
||||
int programNotation, int setfNotation, int systemCase, int systemNotation,
|
||||
VB *sim, uint32_t address, unsigned length, int line
|
||||
) {
|
||||
VBU_DasmConfig config;
|
||||
@@ -121,6 +121,7 @@ EMSCRIPTEN_KEEPALIVE void* Disassemble(
|
||||
config.conditionNotation = conditionNotation;
|
||||
config.hexCase = hexCase;
|
||||
config.hexNotation = hexNotation;
|
||||
config.immediateNotation = immediateNotation;
|
||||
config.memoryNotation = memoryNotation;
|
||||
config.mnemonicCase = mnemonicCase;
|
||||
config.operandOrder = operandOrder;
|
||||
|
||||
Reference in New Issue
Block a user