Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
06849b54ba | ||
|
|
eef255b507 | ||
|
|
db966c8cb8 | ||
|
|
b4feff41f0 | ||
|
|
4449acada0 | ||
|
|
799ac9f51a | ||
|
|
b83b49221d | ||
|
|
27e926bd58 | ||
|
|
d802d39d8d |
@@ -1637,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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -251,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;
|
||||
|
||||
|
||||
+9
-7
@@ -234,7 +234,7 @@ static void vipWriteCell(VB *sim, uint32_t offset, int type, int32_t value) {
|
||||
case VB_S8:
|
||||
case VB_U8:
|
||||
value = offset & 1 ?
|
||||
value << 8 | sim->vip.ram[0x20000 | offset] :
|
||||
value << 8 | sim->vip.ram[0x20001 ^ offset] :
|
||||
value | (int32_t) sim->vip.ram[0x20001 | offset] << 8
|
||||
;
|
||||
break;
|
||||
@@ -284,7 +284,7 @@ static void vipWriteObject(VB *sim, uint32_t offset, int type, int32_t value) {
|
||||
case VB_S8:
|
||||
case VB_U8:
|
||||
value = offset & 1 ?
|
||||
value << 8 | sim->vip.ram[0x3E000 | offset] :
|
||||
value << 8 | sim->vip.ram[0x3E001 ^ offset] :
|
||||
value | (int32_t) sim->vip.ram[0x3E001 | offset] << 8
|
||||
;
|
||||
break;
|
||||
@@ -326,7 +326,7 @@ static void vipWriteWorld(VB *sim, uint32_t offset, int type, int32_t value) {
|
||||
case VB_S8:
|
||||
case VB_U8:
|
||||
value = offset & 1 ?
|
||||
value << 8 | sim->vip.ram[0x3D800 | offset] :
|
||||
value << 8 | sim->vip.ram[0x3D801 ^ offset] :
|
||||
value | (int32_t) sim->vip.ram[0x3D801 | offset] << 8
|
||||
;
|
||||
break;
|
||||
@@ -481,10 +481,12 @@ static void vipWriteIO(
|
||||
break;
|
||||
|
||||
case 0x5F830>>1: /* CTA */
|
||||
if ((mask & 0xFF00) == 0)
|
||||
sim->vip.cta.cta_r = value >> 8;
|
||||
if ((mask & 0x00FF) == 0)
|
||||
sim->vip.cta.cta_l = value;
|
||||
if (debug) {
|
||||
if ((mask & 0xFF00) == 0)
|
||||
sim->vip.cta.cta_r = value >> 8;
|
||||
if ((mask & 0x00FF) == 0)
|
||||
sim->vip.cta.cta_l = value;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x5F842>>1: /* XPCTRL */
|
||||
|
||||
@@ -513,6 +513,8 @@ static int dasmLine(VB *sim, uint32_t *address, uint32_t pc,
|
||||
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;
|
||||
|
||||
@@ -657,6 +659,8 @@ static VBU_DasmLine* dasmDisassemble(VB *sim, uint32_t address,
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
+14
-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(
|
||||
@@ -364,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -436,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(
|
||||
|
||||
Reference in New Issue
Block a user