1 // The SVP chip emulator
3 // (c) Copyright 2008, Grazvydas "notaz" Ignotas
4 // Free for non-commercial use.
6 // For commercial use, separate licencing terms must be obtained.
9 #include "../../pico_int.h"
10 #include "../../cpu/drc/cmn.h"
14 int PicoSVPCycles = 850; // cycles/line, just a guess
15 static int svp_dyn_ready = 0;
17 /* save state stuff */
19 CHUNK_IRAM = CHUNK_CARTHW,
24 static carthw_state_chunk svp_states[] =
26 { CHUNK_IRAM, 0x800, NULL },
27 { CHUNK_DRAM, sizeof(svp->dram), NULL },
28 { CHUNK_SSP, sizeof(svp->ssp1601) - sizeof(svp->ssp1601.drc), NULL },
33 static void PicoSVPReset(void)
35 elprintf(EL_SVP, "SVP reset");
37 memcpy(svp->iram_rom + 0x800, Pico.rom + 0x800, 0x20000 - 0x800);
38 ssp1601_reset(&svp->ssp1601);
40 if ((PicoOpt&POPT_EN_SVP_DRC) && svp_dyn_ready)
41 ssp1601_dyn_reset(&svp->ssp1601);
46 static void PicoSVPLine(void)
49 #if defined(ARM) || defined(PSP)
51 static int delay_lines = 0;
53 if ((Pico.m.scanline&0xf) != 0xf && Pico.m.scanline != 261 && Pico.m.scanline != 311)
60 if ((PicoOpt&POPT_EN_SVP_DRC) && svp_dyn_ready)
61 ssp1601_dyn_run(PicoSVPCycles * count);
65 ssp1601_run(PicoSVPCycles * count);
66 svp_dyn_ready = 0; // just in case
70 //if (Pico.m.frame_count == 13) PicoPad[0] |= 0xff;
74 static int PicoSVPDma(unsigned int source, int len, unsigned short **srcp, unsigned short **limitp)
76 if (source < Pico.romsize) // Rom
79 *srcp = (unsigned short *)(Pico.rom + (source&~1));
80 *limitp = (unsigned short *)(Pico.rom + Pico.romsize);
83 else if ((source & 0xfe0000) == 0x300000)
85 elprintf(EL_VDPDMA|EL_SVP, "SVP DmaSlow from %06x, len=%i", source, len);
88 *srcp = (unsigned short *)(svp->dram + source);
89 *limitp = (unsigned short *)(svp->dram + sizeof(svp->dram));
93 elprintf(EL_VDPDMA|EL_SVP|EL_ANOMALY, "SVP FIXME unhandled DmaSlow from %06x, len=%i", source, len);
99 void PicoSVPInit(void)
102 // this is to unmap tcache and make
103 // mem available for large ROMs, MCD, etc.
108 static void PicoSVPExit(void)
116 void PicoSVPStartup(void)
120 elprintf(EL_STATUS, "SVP startup");
122 ret = PicoCartResize(Pico.romsize + sizeof(*svp));
124 elprintf(EL_STATUS|EL_SVP, "OOM for SVP data");
128 svp = (void *) ((char *)Pico.rom + Pico.romsize);
129 memset(svp, 0, sizeof(*svp));
134 if (PicoOpt & POPT_EN_SVP_DRC) {
135 if (ssp1601_dyn_startup())
141 // init ok, setup hooks..
142 PicoCartMemSetup = PicoSVPMemSetup;
143 PicoDmaHook = PicoSVPDma;
144 PicoResetHook = PicoSVPReset;
145 PicoLineHook = PicoSVPLine;
146 PicoCartUnloadHook = PicoSVPExit;
149 svp_states[0].ptr = svp->iram_rom;
150 svp_states[1].ptr = svp->dram;
151 svp_states[2].ptr = &svp->ssp1601;
152 carthw_chunks = svp_states;