2 * The SVP chip emulator
4 * Copyright (c) GraÅžvydas "notaz" Ignotas, 2008
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the organization nor the
14 * names of its contributors may be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <pico/pico_int.h>
30 #include <cpu/drc/cmn.h>
33 #define SVP_CYCLES_LINE 850
36 static int svp_dyn_ready = 0;
38 /* save state stuff */
40 CHUNK_IRAM = CHUNK_CARTHW,
45 static carthw_state_chunk svp_states[] =
47 { CHUNK_IRAM, 0x800, NULL },
48 { CHUNK_DRAM, sizeof(svp->dram), NULL },
49 { CHUNK_SSP, sizeof(svp->ssp1601) - sizeof(svp->ssp1601.drc), NULL },
54 static void PicoSVPReset(void)
56 elprintf(EL_SVP, "SVP reset");
58 memcpy(svp->iram_rom + 0x800, Pico.rom + 0x800, 0x20000 - 0x800);
59 ssp1601_reset(&svp->ssp1601);
61 if ((PicoIn.opt & POPT_EN_DRC) && svp_dyn_ready)
62 ssp1601_dyn_reset(&svp->ssp1601);
67 static void PicoSVPLine(void)
70 #if defined(__arm__) || defined(PSP)
72 static int delay_lines = 0;
74 if ((Pico.m.scanline&0xf) != 0xf && Pico.m.scanline != 261 && Pico.m.scanline != 311)
81 if ((PicoIn.opt & POPT_EN_DRC) && svp_dyn_ready)
82 ssp1601_dyn_run(SVP_CYCLES_LINE * count);
86 ssp1601_run(SVP_CYCLES_LINE * count);
87 svp_dyn_ready = 0; // just in case
91 //if (Pico.m.frame_count == 13) PicoIn.pad[0] |= 0xff;
95 static int PicoSVPDma(unsigned int source, int len, unsigned short **base, unsigned int *mask)
97 if (source < Pico.romsize) // Rom
99 *base = (unsigned short *)(Pico.rom + (source & 0xfe0000));
103 else if ((source & 0xfe0000) == 0x300000)
105 elprintf(EL_VDPDMA|EL_SVP, "SVP DmaSlow from %06x, len=%i", source, len);
106 *base = (unsigned short *)svp->dram;
111 elprintf(EL_VDPDMA|EL_SVP|EL_ANOMALY, "SVP FIXME unhandled DmaSlow from %06x, len=%i", source, len);
117 void PicoSVPInit(void)
120 // this is to unmap tcache and make
121 // mem available for large ROMs, MCD, etc.
126 static void PicoSVPExit(void)
134 void PicoSVPStartup(void)
138 elprintf(EL_STATUS, "SVP startup");
140 ret = PicoCartResize(Pico.romsize + sizeof(*svp));
142 elprintf(EL_STATUS|EL_SVP, "OOM for SVP data");
146 svp = (void *) ((char *)Pico.rom + Pico.romsize);
147 memset(svp, 0, sizeof(*svp));
152 if (PicoIn.opt & POPT_EN_DRC) {
153 if (ssp1601_dyn_startup())
159 // init ok, setup hooks..
160 PicoCartMemSetup = PicoSVPMemSetup;
161 PicoDmaHook = PicoSVPDma;
162 PicoResetHook = PicoSVPReset;
163 PicoLineHook = PicoSVPLine;
164 PicoCartUnloadHook = PicoSVPExit;
167 svp_states[0].ptr = svp->iram_rom;
168 svp_states[1].ptr = svp->dram;
169 svp_states[2].ptr = &svp->ssp1601;
170 carthw_chunks = svp_states;
171 PicoIn.AHW |= PAHW_SVP;