some more SVP work

git-svn-id: file:///home/notaz/opt/svn/PicoDrive@319 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2007-12-26 19:00:46 +00:00
parent f8ef8ff710
commit 017512f282
8 changed files with 373 additions and 93 deletions

View file

@ -496,6 +496,7 @@ int PicoCartInsert(unsigned char *rom,unsigned int romsize)
PicoMemResetHooks(); PicoMemResetHooks();
PicoDmaHook = NULL; PicoDmaHook = NULL;
PicoResetHook = NULL; PicoResetHook = NULL;
PicoLineHook = NULL;
if (!(PicoMCD & 1)) if (!(PicoMCD & 1))
PicoCartDetect(); PicoCartDetect();

View file

@ -19,6 +19,7 @@ int PicoAutoRgnOrder = 0;
int emustatus = 0; // rapid_ym2612, multi_ym_updates int emustatus = 0; // rapid_ym2612, multi_ym_updates
void (*PicoWriteSound)(int len) = NULL; // called at the best time to send sound buffer (PsndOut) to hardware void (*PicoWriteSound)(int len) = NULL; // called at the best time to send sound buffer (PsndOut) to hardware
void (*PicoResetHook)(void) = NULL; void (*PicoResetHook)(void) = NULL;
void (*PicoLineHook)(void) = NULL;
struct PicoSRAM SRam = {0,}; struct PicoSRAM SRam = {0,};
int z80startCycle, z80stopCycle; // in 68k cycles int z80startCycle, z80stopCycle; // in 68k cycles

View file

@ -149,6 +149,8 @@ static int PicoFrameHints(void)
#ifdef PICO_CD #ifdef PICO_CD
update_chips(); update_chips();
#else
if (PicoLineHook) PicoLineHook();
#endif #endif
} }
@ -210,7 +212,9 @@ static int PicoFrameHints(void)
CYCLES_Z80_LINE - CYCLES_Z80_ASD, CYCLES_S68K_LINE - CYCLES_S68K_ASD); CYCLES_Z80_LINE - CYCLES_Z80_ASD, CYCLES_S68K_LINE - CYCLES_S68K_ASD);
#ifdef PICO_CD #ifdef PICO_CD
update_chips(); update_chips();
#else
if (PicoLineHook) PicoLineHook();
#endif #endif
// PAL line count might actually be 313 according to Steve Snake, but that would complicate things. // PAL line count might actually be 313 according to Steve Snake, but that would complicate things.
@ -234,6 +238,8 @@ static int PicoFrameHints(void)
#ifdef PICO_CD #ifdef PICO_CD
update_chips(); update_chips();
#else
if (PicoLineHook) PicoLineHook();
#endif #endif
} }

View file

@ -410,6 +410,7 @@ extern struct PicoSRAM SRam;
extern int emustatus; extern int emustatus;
extern int z80startCycle, z80stopCycle; // in 68k cycles extern int z80startCycle, z80stopCycle; // in 68k cycles
extern void (*PicoResetHook)(void); extern void (*PicoResetHook)(void);
extern void (*PicoLineHook)(void);
PICO_INTERNAL int CheckDMA(void); PICO_INTERNAL int CheckDMA(void);
// cd/Pico.c // cd/Pico.c
@ -476,23 +477,24 @@ PICO_INTERNAL void z80_exit(void);
#define EL_LOGMASK 0 #define EL_LOGMASK 0
#endif #endif
#define EL_HVCNT 0x0001 /* hv counter reads */ #define EL_HVCNT 0x00000001 /* hv counter reads */
#define EL_SR 0x0002 /* SR reads */ #define EL_SR 0x00000002 /* SR reads */
#define EL_INTS 0x0004 /* ints and acks */ #define EL_INTS 0x00000004 /* ints and acks */
#define EL_YM2612R 0x0008 /* 68k ym2612 reads */ #define EL_YM2612R 0x00000008 /* 68k ym2612 reads */
#define EL_INTSW 0x0010 /* log irq switching on/off */ #define EL_INTSW 0x00000010 /* log irq switching on/off */
#define EL_ASVDP 0x0020 /* VDP accesses during active scan */ #define EL_ASVDP 0x00000020 /* VDP accesses during active scan */
#define EL_VDPDMA 0x0040 /* VDP DMA transfers and their timing */ #define EL_VDPDMA 0x00000040 /* VDP DMA transfers and their timing */
#define EL_BUSREQ 0x0080 /* z80 busreq r/w or reset w */ #define EL_BUSREQ 0x00000080 /* z80 busreq r/w or reset w */
#define EL_Z80BNK 0x0100 /* z80 i/o through bank area */ #define EL_Z80BNK 0x00000100 /* z80 i/o through bank area */
#define EL_SRAMIO 0x0200 /* sram i/o */ #define EL_SRAMIO 0x00000200 /* sram i/o */
#define EL_EEPROM 0x0400 /* eeprom debug */ #define EL_EEPROM 0x00000400 /* eeprom debug */
#define EL_UIO 0x0800 /* unmapped i/o */ #define EL_UIO 0x00000800 /* unmapped i/o */
#define EL_IO 0x1000 /* all i/o */ #define EL_IO 0x00001000 /* all i/o */
#define EL_CDPOLL 0x2000 /* MCD: log poll detection */ #define EL_CDPOLL 0x00002000 /* MCD: log poll detection */
#define EL_SVP 0x00004000 /* SVP stuff */
#define EL_STATUS 0x4000 /* status messages */ #define EL_STATUS 0x40000000 /* status messages */
#define EL_ANOMALY 0x8000 /* some unexpected conditions (during emulation) */ #define EL_ANOMALY 0x80000000 /* some unexpected conditions (during emulation) */
#if EL_LOGMASK #if EL_LOGMASK
extern void lprintf(const char *fmt, ...); extern void lprintf(const char *fmt, ...);

View file

@ -11,11 +11,8 @@ typedef struct {
extern svp_t *svp; extern svp_t *svp;
void PicoSVPInit(void); void PicoSVPInit(void);
void PicoSVPReset(void);
unsigned int PicoSVPRead16(unsigned int a, int realsize); unsigned int PicoSVPRead16(unsigned int a, int realsize);
void PicoSVPWrite8 (unsigned int a, unsigned int d, int realsize); void PicoSVPWrite8 (unsigned int a, unsigned int d, int realsize);
void PicoSVPWrite16(unsigned int a, unsigned int d, int realsize); void PicoSVPWrite16(unsigned int a, unsigned int d, int realsize);
int PicoSVPDma(unsigned int source, unsigned short **srcp, unsigned short **limitp);

View file

@ -131,85 +131,343 @@
* mpys (rj), (ri), b * mpys (rj), (ri), b
* name: multiply and subtract? * name: multiply and subtract?
* notes: not used by VR code. * notes: not used by VR code.
*
*
* Assumptions in this code
* P is not directly writeable
*/ */
#include "../../PicoInt.h" #include "../../PicoInt.h"
#define rX ssp->gr[SSP_X].l #define u32 unsigned int
#define rY ssp->gr[SSP_Y].l
#define rA ssp->gr[SSP_A] // 4 // 0
#define rST ssp->gr[SSP_ST].l #define rX ssp->gr[SSP_X].h
#define rSTACK ssp->gr[SSP_STACK].l #define rY ssp->gr[SSP_Y].h
#define rPC ssp->gr[SSP_PC].l #define rA ssp->gr[SSP_A].h
#define rP ssp->gr[SSP_P] // 8 #define rST ssp->gr[SSP_ST].h // 4
#define rPM0 ssp->gr[SSP_PM0].l #define rSTACK ssp->gr[SSP_STACK].h
#define rPM1 ssp->gr[SSP_PM1].l #define rPC ssp->gr[SSP_PC].h
#define rPM2 ssp->gr[SSP_PM2].l #define rP ssp->gr[SSP_P]
#define rXST ssp->gr[SSP_XST].l // 12 #define rPM0 ssp->gr[SSP_PM0].h // 8
#define rPM4 ssp->gr[SSP_PM4].l // 14 #define rPM1 ssp->gr[SSP_PM1].h
#define rPMC ssp->gr[SSP_PMC].l #define rPM2 ssp->gr[SSP_PM2].h
#define rXST ssp->gr[SSP_XST].h
#define rPM4 ssp->gr[SSP_PM4].h // 12
// 13
#define rPMC ssp->gr[SSP_PMC] // will keep addr in .h, mode in .l
#define rAL ssp->gr[SSP_A].l #define rAL ssp->gr[SSP_A].l
#define GET_PC() (PC - (unsigned short *)Pico.rom) #define GET_PC() (PC - (unsigned short *)Pico.rom)
#define SET_PC() PC = (unsigned short *)Pico.rom + rPC #define GET_PC_OFFS() ((unsigned int)PC - (unsigned int)Pico.rom)
#define SET_PC(d) PC = (unsigned short *)Pico.rom + d
void ssp1601_reset(ssp1601_t *ssp) #define REG_READ(r) (((r) <= 4) ? ssp->gr[r].h : read_handlers[r]())
#define REG_WRITE(r,d) { \
int r1 = r; \
if (r1 > 4) write_handlers[r1](d); \
else if (r1 > 0) ssp->gr[r1].h = d; \
}
static ssp1601_t *ssp = NULL;
static unsigned short *PC;
static int g_cycles;
// -----------------------------------------------------
// register i/o handlers
// 0-4, 13
static u32 read_unknown(void)
{ {
ssp->emu_status = 0; elprintf(EL_ANOMALY|EL_SVP, "ssp16: unknown read @ %04x", GET_PC_OFFS());
ssp->gr[SSP_GR0].v = 0xffff; return 0;
rPC = 0x400; }
rSTACK = 5; // ?
static void write_unknown(u32 d)
{
elprintf(EL_ANOMALY|EL_SVP, "ssp16: unknown write @ %04x", GET_PC_OFFS());
}
// 5
static u32 read_STACK(void)
{
u32 d = 0;
if (rSTACK < 6) {
d = ssp->stack[rSTACK];
rSTACK++;
} else
elprintf(EL_ANOMALY|EL_SVP, "ssp16: stack underflow! (%i) @ %04x", rSTACK, GET_PC_OFFS());
return d;
}
static void write_STACK(u32 d)
{
if (rSTACK > 0) {
rSTACK--;
ssp->stack[rSTACK] = d;
} else
elprintf(EL_ANOMALY|EL_SVP, "ssp16: stack overflow! (%i) @ %04x", rSTACK, GET_PC_OFFS());
}
// 6
static u32 read_PC(void)
{
return GET_PC();
}
static void write_PC(u32 d)
{
SET_PC(d);
g_cycles--;
}
// 7
static u32 read_P(void)
{
rP.v = (u32)rX * rY * 2;
return rP.h;
}
static u32 pm_io(int reg, int write, u32 d)
{
if (ssp->emu_status & SSP_PMC_SET) {
elprintf(EL_SVP, "PM%i (%c) set to %08x @ %04x", reg, write ? 'w' : 'r', rPMC.v, GET_PC_OFFS());
ssp->pmac_read[write ? reg + 6 : reg] = rPMC.v;
ssp->emu_status &= ~SSP_PMC_SET;
return 0;
}
if (ssp->pmac_read[reg] != 0) {
elprintf(EL_SVP, "PM%i %c @ %04x", reg, write ? 'w' : 'r', GET_PC_OFFS());
// do something depending on mode
return 0;
}
return (u32)-1;
}
// 8
static u32 read_PM0(void)
{
u32 d = pm_io(0, 0, 0);
if (d != (u32)-1) return d;
elprintf(EL_SVP, "PM0 raw r %04x @ %04x", rPM0, GET_PC_OFFS());
return rPM0;
}
static void write_PM0(u32 d)
{
u32 r = pm_io(0, 1, d);
if (r != (u32)-1) return;
elprintf(EL_SVP, "PM0 raw w %04x @ %04x", d, GET_PC_OFFS());
rPM0 = d;
}
// 9
static u32 read_PM1(void)
{
u32 d = pm_io(1, 0, 0);
if (d != (u32)-1) return d;
// can be removed?
elprintf(EL_SVP, "PM1 raw r %04x @ %04x", rPM1, GET_PC_OFFS());
return rPM0;
}
static void write_PM1(u32 d)
{
u32 r = pm_io(1, 1, d);
if (r != (u32)-1) return;
// can be removed?
elprintf(EL_SVP, "PM1 raw w %04x @ %04x", d, GET_PC_OFFS());
rPM0 = d;
}
// 10
static u32 read_PM2(void)
{
u32 d = pm_io(2, 0, 0);
if (d != (u32)-1) return d;
// can be removed?
elprintf(EL_SVP, "PM2 raw r %04x @ %04x", rPM2, GET_PC_OFFS());
return rPM0;
}
static void write_PM2(u32 d)
{
u32 r = pm_io(2, 1, d);
if (r != (u32)-1) return;
// can be removed?
elprintf(EL_SVP, "PM2 raw w %04x @ %04x", d, GET_PC_OFFS());
rPM0 = d;
}
// 11
static u32 read_XST(void)
{
// can be removed?
u32 d = pm_io(3, 0, 0);
if (d != (u32)-1) return d;
elprintf(EL_SVP, "XST raw r %04x @ %04x", rXST, GET_PC_OFFS());
return rPM0;
}
static void write_XST(u32 d)
{
// can be removed?
u32 r = pm_io(3, 1, d);
if (r != (u32)-1) return;
elprintf(EL_SVP, "XST raw w %04x @ %04x", d, GET_PC_OFFS());
rPM0 = d;
}
// 12
static u32 read_PM4(void)
{
u32 d = pm_io(4, 0, 0);
if (d != (u32)-1) return d;
// can be removed?
elprintf(EL_SVP, "PM4 raw r %04x @ %04x", rPM4, GET_PC_OFFS());
return rPM0;
}
static void write_PM4(u32 d)
{
u32 r = pm_io(4, 1, d);
if (r != (u32)-1) return;
// can be removed?
elprintf(EL_SVP, "PM4 raw w %04x @ %04x", d, GET_PC_OFFS());
rPM0 = d;
}
// 14
static u32 read_PMC(void)
{
if (ssp->emu_status & SSP_PMC_HAVE_ADDR) {
if (ssp->emu_status & SSP_PMC_SET)
elprintf(EL_ANOMALY|EL_SVP, "prev PMC not used @ %04x", GET_PC_OFFS());
ssp->emu_status |= SSP_PMC_SET;
return rPMC.l;
} else {
ssp->emu_status |= SSP_PMC_HAVE_ADDR;
return rPMC.h;
}
}
static void write_PMC(u32 d)
{
if (ssp->emu_status & SSP_PMC_HAVE_ADDR) {
if (ssp->emu_status & SSP_PMC_SET)
elprintf(EL_ANOMALY|EL_SVP, "prev PMC not used @ %04x", GET_PC_OFFS());
ssp->emu_status |= SSP_PMC_SET;
rPMC.l = d;
} else {
ssp->emu_status |= SSP_PMC_HAVE_ADDR;
rPMC.h = d;
}
}
// 15
static u32 read_AL(void)
{
// TODO: figure out what's up with those blind reads..
return rAL;
}
static void write_AL(u32 d)
{
rAL = d;
} }
void ssp1601_run(ssp1601_t *ssp, int cycles) typedef u32 (*read_func_t)(void);
typedef void (*write_func_t)(u32 d);
static read_func_t read_handlers[16] =
{
read_unknown, read_unknown, read_unknown, read_unknown, // -, X, Y, A
read_unknown, // 4 ST
read_STACK,
read_PC,
read_P,
read_PM0, // 8
read_PM1,
read_PM2,
read_XST,
read_PM4, // 12
read_unknown, // 13 gr13
read_PMC,
read_AL
};
static write_func_t write_handlers[16] =
{
write_unknown, write_unknown, write_unknown, write_unknown, // -, X, Y, A
write_unknown, // 4 ST
write_STACK,
write_PC,
write_unknown, // 7 P
write_PM0, // 8
write_PM1,
write_PM2,
write_XST,
write_PM4, // 12
write_unknown, // 13 gr13
write_PMC,
write_AL
};
void ssp1601_reset(ssp1601_t *l_ssp)
{
ssp = l_ssp;
ssp->emu_status = 0;
ssp->gr[SSP_GR0].v = 0xffff0000;
rPC = 0x400;
rSTACK = 6; // ? using descending stack
}
void ssp1601_run(int cycles)
{ {
unsigned short *PC;
int op; int op;
SET_PC(); SET_PC(rPC);
g_cycles = cycles;
while (cycles > 0) while (g_cycles > 0)
{ {
op = *PC; op = *PC;
switch (op >> 9) switch (op >> 9)
{ {
// ld d, s // ld d, s
case 0: case 0:
{
int s, d, opdata = 0;
if (op == 0) break; // nop if (op == 0) break; // nop
s = op & 0x0f; if (op == ((SSP_A<<4)|SSP_P)) { // A <- P
d = (op & 0xf0) >> 4; // not sure. MAME claims that only hi word is transfered.
if (s == SSP_A || s == SSP_P) opdata |= 1; // src is 32bit read_P(); // update P
if (d == SSP_A || d == SSP_P) opdata |= 2; // dst is 32bit ssp->gr[SSP_A].v = ssp->gr[SSP_P].v;
if (s == SSP_STACK) opdata |= 4; // src is stack break;
if (d == SSP_STACK) opdata |= 8; // dst is stack
switch (opdata)
{
case 0x0: ssp->gr[d].l = ssp->gr[s].l; break; // 16 <- 16
case 0x1: ssp->gr[d].l = ssp->gr[s].h; break; // 16 <- 32
case 0x2: ssp->gr[d].h = ssp->gr[s].l; break; // 32 <- 16
// TODO: MAME claims that only hi word is transfered. Go figure.
case 0x3: ssp->gr[d].v = ssp->gr[s].v; break; // 32 <- 32
case 0x4: ; // TODO
} }
if (d == SSP_PC)
{ {
SET_PC(); u32 d = REG_READ(op & 0x0f);
cycles--; REG_WRITE((op & 0xf0) >> 4, d);
} }
// flags?
break; break;
}
default: default:
elprintf(0xffff, "ssp: unhandled op %04x @ %04x", op, GET_PC()<<1); elprintf(EL_ANOMALY|EL_SVP, "ssp16: unhandled op %04x @ %04x", op, GET_PC_OFFS());
break; break;
} }
cycles--; g_cycles--;
PC++; PC++;
} }
read_P(); // update P
rPC = GET_PC(); rPC = GET_PC();
if (ssp->gr[SSP_GR0].v != 0xffff0000)
elprintf(EL_ANOMALY|EL_SVP, "ssp16: REG 0 corruption! %08x", ssp->gr[SSP_GR0].v);
} }

View file

@ -34,13 +34,16 @@ typedef struct
}; };
}; };
unsigned short stack[6]; unsigned short stack[6];
unsigned int pmac_read[6]; // read modes/addrs for PM0-PM5
unsigned int pmac_write[6]; // write ...
// //
#define SSP_PMC_HAVE_ADDR 1 // address written to PMAC, waiting for mode #define SSP_PMC_HAVE_ADDR 1 // address written to PMAC, waiting for mode
#define SSP_PMC_SET 2 // PMAC is set
unsigned int emu_status; unsigned int emu_status;
unsigned int pad[10]; unsigned int pad[30];
} ssp1601_t; } ssp1601_t;
void ssp1601_reset(ssp1601_t *ssp); void ssp1601_reset(ssp1601_t *ssp);
void ssp1601_run(ssp1601_t *ssp, int cycles); void ssp1601_run(int cycles);

View file

@ -2,16 +2,49 @@
svp_t *svp = NULL; svp_t *svp = NULL;
static void PicoSVPReset(void)
{
elprintf(EL_SVP, "SVP reset");
ssp1601_reset(&svp->ssp1601);
}
static void PicoSVPLine(void)
{
// ???
// OSC_NTSC / 3.0 / 60.0 / 262.0 ~= 1139
// OSC_PAL / 3.0 / 50.0 / 312.0 ~= 1137
ssp1601_run(100);
exit(1);
}
static int PicoSVPDma(unsigned int source, unsigned short **srcp, unsigned short **limitp)
{
if ((source & 0xfe0000) == 0x300000)
{
elprintf(EL_VDPDMA|EL_SVP, "SVP DmaSlow from %06x", source);
source &= 0x1fffe;
*srcp = (unsigned short *)(svp->ram + source);
*limitp = (unsigned short *)(svp->ram + sizeof(svp->ram));
return 1;
}
return 0;
}
void PicoSVPInit(void) void PicoSVPInit(void)
{ {
void *tmp; void *tmp;
elprintf(0xffff, "SVP init"); elprintf(EL_SVP, "SVP init");
tmp = realloc(Pico.rom, 0x200000 + sizeof(*svp)); tmp = realloc(Pico.rom, 0x200000 + sizeof(*svp));
if (tmp == NULL) if (tmp == NULL)
{ {
elprintf(EL_STATUS, "OOM for SVP data"); elprintf(EL_STATUS|EL_SVP, "OOM for SVP data");
return; return;
} }
@ -24,28 +57,7 @@ void PicoSVPInit(void)
PicoWrite8Hook = PicoSVPWrite8; PicoWrite8Hook = PicoSVPWrite8;
PicoWrite16Hook = PicoSVPWrite16; PicoWrite16Hook = PicoSVPWrite16;
PicoDmaHook = PicoSVPDma; PicoDmaHook = PicoSVPDma;
} PicoResetHook = PicoSVPReset;
PicoLineHook = PicoSVPLine;
void PicoSVPReset(void)
{
elprintf(0xffff, "SVP reset");
ssp1601_reset(&svp->ssp1601);
}
int PicoSVPDma(unsigned int source, unsigned short **srcp, unsigned short **limitp)
{
if ((source & 0xfe0000) == 0x300000)
{
elprintf(EL_VDPDMA|0xffff, "SVP DmaSlow from %06x", source);
source &= 0x1fffe;
*srcp = (unsigned short *)(svp->ram + source);
*limitp = (unsigned short *)(svp->ram + sizeof(svp->ram));
return 1;
}
return 0;
} }