Implement communication port
This commit is contained in:
@@ -146,6 +146,28 @@ struct VB {
|
||||
int step; /* Operation sub-task ID */
|
||||
} cpu;
|
||||
|
||||
/* Communication port */
|
||||
struct {
|
||||
|
||||
/* Register state */
|
||||
uint8_t c_clk_sel; /* Transmission clock source */
|
||||
uint8_t c_int_inh; /* Interrupt acknowledge/disable */
|
||||
uint8_t c_stat; /* Communication is underway */
|
||||
uint8_t cc_int_inh; /* Interrupt acknowledge/disable */
|
||||
uint8_t cc_int_lev; /* Interrupt condition */
|
||||
uint8_t cc_rd; /* Manual read */
|
||||
uint8_t cc_sig; /* Automatic write */
|
||||
uint8_t cc_smp; /* Automatic read */
|
||||
uint8_t cc_wr; /* Manual write */
|
||||
uint8_t cdrr; /* Data received */
|
||||
uint8_t cdtr; /* Data to transmit */
|
||||
|
||||
/* Other state */
|
||||
int8_t c_irq; /* COM interrupt request */
|
||||
int8_t cc_irq; /* COMCNT interrupt request */
|
||||
uint32_t clocks; /* Master clocks to wait */
|
||||
} ext;
|
||||
|
||||
/* Game pad */
|
||||
struct {
|
||||
|
||||
@@ -159,8 +181,9 @@ struct VB {
|
||||
uint8_t soft_ck; /* Controller communication signal */
|
||||
|
||||
/* Other state */
|
||||
uint16_t keys; /* Next input bits */
|
||||
int step; /* Software read processing phase */
|
||||
uint32_t clocks; /* Master clocks to wait */
|
||||
uint16_t keys; /* Next input bits */
|
||||
int step; /* Software read processing phase */
|
||||
} pad;
|
||||
|
||||
/* Timer */
|
||||
@@ -310,6 +333,12 @@ struct VB {
|
||||
int sample; /* Output sample index, period 417 */
|
||||
} vsu;
|
||||
|
||||
/* Wait controller */
|
||||
struct {
|
||||
uint8_t exp1w; /* Cartridge expansion 1-wait */
|
||||
uint8_t rom1w; /* Cartridge ROM 1-wait */
|
||||
} wcr;
|
||||
|
||||
/* Pseudo-halt */
|
||||
struct {
|
||||
uint32_t address; /* Monitor address */
|
||||
@@ -335,7 +364,6 @@ struct VB {
|
||||
} ph;
|
||||
|
||||
/* Other state */
|
||||
uint8_t wcr; /* Wait controller state */
|
||||
uint8_t wram[0x10000]; /* System RAM */
|
||||
|
||||
/* Application data */
|
||||
@@ -343,9 +371,11 @@ struct VB {
|
||||
vbOnExecute onExecute; /* CPU instruction execute */
|
||||
vbOnFetch onFetch; /* CPU instruction fetch */
|
||||
vbOnFrame onFrame; /* VIP frame ready */
|
||||
vbOnLink onLink; /* Communication transfer */
|
||||
vbOnRead onRead; /* CPU instruction read */
|
||||
vbOnSamples onSamples; /* VSU samples full */
|
||||
vbOnWrite onWrite; /* CPU instruction write */
|
||||
VB *peer; /* Communication peer */
|
||||
void *tag; /* User data */
|
||||
};
|
||||
|
||||
@@ -368,6 +398,7 @@ static int32_t SignExtend(int32_t value, int32_t bits) {
|
||||
|
||||
/******************************** Sub-Modules ********************************/
|
||||
|
||||
#include "ext.c"
|
||||
#include "game-pad.c"
|
||||
#include "timer.c"
|
||||
#include "bus.c"
|
||||
@@ -391,7 +422,8 @@ static int sysEmulate(VB *sim, uint32_t clocks) {
|
||||
;
|
||||
|
||||
/* Process all components */
|
||||
if (!never) ret = cpuEmulate(sim, clocks);
|
||||
if (!never){ret = cpuEmulate(sim, clocks);}
|
||||
ret |= extEmulate(sim, clocks);
|
||||
padEmulate(sim, clocks);
|
||||
tmrEmulate(sim, clocks);
|
||||
vsuEmulate(sim, clocks);
|
||||
@@ -403,6 +435,7 @@ static int sysEmulate(VB *sim, uint32_t clocks) {
|
||||
/* Determine how many clocks are guaranteed to process */
|
||||
static uint32_t sysUntil(VB *sim, uint32_t clocks) {
|
||||
clocks = cpuUntil(sim, clocks);
|
||||
clocks = extUntil(sim, clocks);
|
||||
clocks = padUntil(sim, clocks);
|
||||
clocks = tmrUntil(sim, clocks);
|
||||
clocks = vipUntil(sim, clocks);
|
||||
@@ -487,6 +520,11 @@ VBAPI uint16_t vbGetKeys(VB *sim) {
|
||||
return sim->pad.keys;
|
||||
}
|
||||
|
||||
/* Retrieve the current link callback handler */
|
||||
VBAPI vbOnLink vbGetLinkCallback(VB *sim) {
|
||||
return sim->onLink;
|
||||
}
|
||||
|
||||
/* Retrieve a core option value */
|
||||
VBAPI int vbGetOption(VB *sim, int key) {
|
||||
switch (key) {
|
||||
@@ -495,6 +533,11 @@ VBAPI int vbGetOption(VB *sim, int key) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Retrieve the communication peer */
|
||||
VBAPI VB* vbGetPeer(VB *sim) {
|
||||
return sim->peer;
|
||||
}
|
||||
|
||||
/* Retrieve the most recent frame image pixels */
|
||||
VBAPI void vbGetPixels(VB *sim, void *left, int leftStrideX, int leftStrideY,
|
||||
void *right, int rightStrideX, int rightStrideY) {
|
||||
@@ -594,9 +637,11 @@ VBAPI VB* vbInit(VB *sim) {
|
||||
sim->onExecute = NULL;
|
||||
sim->onFetch = NULL;
|
||||
sim->onFrame = NULL;
|
||||
sim->onLink = NULL;
|
||||
sim->onRead = NULL;
|
||||
sim->onSamples = NULL;
|
||||
sim->onWrite = NULL;
|
||||
sim->peer = NULL;
|
||||
sim->ph.enabled = 0;
|
||||
vbReset(sim);
|
||||
return sim;
|
||||
@@ -616,7 +661,8 @@ VBAPI VB* vbReset(VB *sim) {
|
||||
int x; /* Iterator */
|
||||
|
||||
/* Wait controller */
|
||||
sim->wcr = 0x00;
|
||||
sim->wcr.exp1w = 0;
|
||||
sim->wcr.rom1w = 0;
|
||||
|
||||
/* WRAM (the hardware does not do this) */
|
||||
for (x = 0; x < 0x10000; x++)
|
||||
@@ -624,6 +670,7 @@ VBAPI VB* vbReset(VB *sim) {
|
||||
|
||||
/* Components */
|
||||
cpuReset(sim);
|
||||
extReset(sim);
|
||||
padReset(sim);
|
||||
tmrReset(sim);
|
||||
vipReset(sim);
|
||||
@@ -689,6 +736,13 @@ VBAPI uint16_t vbSetKeys(VB *sim, uint16_t keys) {
|
||||
return sim->pad.keys = keys;
|
||||
}
|
||||
|
||||
/* Specify a new link callback handler */
|
||||
VBAPI vbOnLink vbSetLinkCallback(VB *sim, vbOnLink callback) {
|
||||
vbOnLink prev = sim->onLink;
|
||||
sim->onLink = callback;
|
||||
return prev;
|
||||
}
|
||||
|
||||
/* Specify a new core option value */
|
||||
VBAPI int vbSetOption(VB *sim, int key, int value) {
|
||||
switch (key) {
|
||||
@@ -706,6 +760,15 @@ VBAPI int vbSetOption(VB *sim, int key, int value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
/* Specify a new communication peer */
|
||||
VBAPI VB* vbSetPeer(VB *sim, VB *peer) {
|
||||
VB *prev = sim->peer;
|
||||
sim->peer = peer;
|
||||
if (peer != prev && prev != NULL)
|
||||
prev->peer = NULL;
|
||||
return prev;
|
||||
}
|
||||
|
||||
/* Specify a new value for the program counter */
|
||||
VBAPI uint32_t vbSetProgramCounter(VB *sim, uint32_t value) {
|
||||
sim->cpu.operation = CPU_FETCH;
|
||||
|
||||
Reference in New Issue
Block a user