Implement game pad and timer
This commit is contained in:
@@ -90,6 +90,39 @@ struct VB {
|
||||
int step; /* Operation sub-task ID */
|
||||
} cpu;
|
||||
|
||||
/* Game pad */
|
||||
struct {
|
||||
|
||||
/* Hardware state */
|
||||
uint8_t k_int_inh; /* Interrupt acknowledge/disable */
|
||||
uint8_t para_si; /* Read reset signal */
|
||||
uint8_t s_abt_dis; /* Abort hardware read */
|
||||
uint8_t sdhr; /* High key bits */
|
||||
uint8_t sdlr; /* Low key bits */
|
||||
uint32_t si_stat; /* Hardware read in progress */
|
||||
uint8_t soft_ck; /* Controller communication signal */
|
||||
|
||||
/* Simulation state */
|
||||
uint8_t keys; /* Next input bits */
|
||||
int step; /* Software read processing phase */
|
||||
} pad;
|
||||
|
||||
/* Timer */
|
||||
struct {
|
||||
|
||||
/* Hardware state */
|
||||
uint8_t t_clk_sel; /* Counter tick duration */
|
||||
uint8_t t_enb; /* Enable timer */
|
||||
uint8_t tim_z_int; /* Enable interrupt */
|
||||
uint8_t z_stat; /* Zero status */
|
||||
|
||||
/* Simulation state */
|
||||
uint32_t clocks; /* Master clocks to wait */
|
||||
uint16_t counter; /* Current counter value */
|
||||
uint16_t reload; /* Reload counter value */
|
||||
uint32_t until; /* Clocks until interrupt condition */
|
||||
} tmr;
|
||||
|
||||
/* VIP */
|
||||
struct {
|
||||
|
||||
@@ -168,6 +201,7 @@ struct VB {
|
||||
} vip;
|
||||
|
||||
/* Other state */
|
||||
uint8_t wcr; /* Wait controller state */
|
||||
uint8_t wram[0x10000]; /* System RAM */
|
||||
|
||||
/* Application data */
|
||||
@@ -199,6 +233,8 @@ static int32_t SignExtend(int32_t value, int32_t bits) {
|
||||
|
||||
/******************************** Sub-Modules ********************************/
|
||||
|
||||
#include "game-pad.c"
|
||||
#include "timer.c"
|
||||
#include "bus.c"
|
||||
#include "cpu.c"
|
||||
#include "vip.c"
|
||||
@@ -211,7 +247,9 @@ static int32_t SignExtend(int32_t value, int32_t bits) {
|
||||
static int sysEmulate(VB *sim, uint32_t clocks) {
|
||||
return
|
||||
cpuEmulate(sim, clocks) |
|
||||
vipEmulate(sim, clocks)
|
||||
vipEmulate(sim, clocks) |
|
||||
padEmulate(sim, clocks) |
|
||||
tmrEmulate(sim, clocks)
|
||||
;
|
||||
}
|
||||
|
||||
@@ -219,6 +257,8 @@ static int sysEmulate(VB *sim, uint32_t clocks) {
|
||||
static uint32_t sysUntil(VB *sim, uint32_t clocks) {
|
||||
clocks = cpuUntil(sim, clocks);
|
||||
clocks = vipUntil(sim, clocks);
|
||||
clocks = padUntil(sim, clocks);
|
||||
clocks = tmrUntil(sim, clocks);
|
||||
return clocks;
|
||||
}
|
||||
|
||||
@@ -295,6 +335,11 @@ VBAPI vbOnFrame vbGetFrameCallback(VB *sim) {
|
||||
return sim->onFrame;
|
||||
}
|
||||
|
||||
/* Retrieve the current game pad key state */
|
||||
VBAPI uint16_t vbGetKeys(VB *sim) {
|
||||
return sim->pad.keys;
|
||||
}
|
||||
|
||||
/* Retrieve the most recent frame image pixels */
|
||||
VBAPI void vbGetPixels(VB *sim, void *left, int leftStrideX, int leftStrideY,
|
||||
void *right, int rightStrideX, int rightStrideY) {
|
||||
@@ -391,6 +436,9 @@ VBAPI int32_t vbRead(VB *sim, uint32_t address, int type) {
|
||||
VBAPI VB* vbReset(VB *sim) {
|
||||
int x; /* Iterator */
|
||||
|
||||
/* Wait controller */
|
||||
sim->wcr = 0x00;
|
||||
|
||||
/* WRAM (the hardware does not do this) */
|
||||
for (x = 0; x < 0x10000; x++)
|
||||
sim->wram[x] = 0x00;
|
||||
@@ -398,6 +446,8 @@ VBAPI VB* vbReset(VB *sim) {
|
||||
/* Components */
|
||||
cpuReset(sim);
|
||||
vipReset(sim);
|
||||
padReset(sim);
|
||||
tmrReset(sim);
|
||||
return sim;
|
||||
}
|
||||
|
||||
@@ -451,6 +501,11 @@ VBAPI vbOnFrame vbSetFrameCallback(VB *sim, vbOnFrame callback) {
|
||||
return prev;
|
||||
}
|
||||
|
||||
/* Specify new game pad keys */
|
||||
VBAPI uint16_t vbSetKeys(VB *sim, uint16_t keys) {
|
||||
return sim->pad.keys = keys;
|
||||
}
|
||||
|
||||
/* 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