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"
11 #if defined(__linux__) && defined(ARM)
16 int PicoSVPCycles = 850; // cycles/line, just a guess
17 static int svp_dyn_ready = 0;
19 /* save state stuff */
21 CHUNK_IRAM = CHUNK_CARTHW,
26 static carthw_state_chunk svp_states[] =
28 { CHUNK_IRAM, 0x800, NULL },
29 { CHUNK_DRAM, sizeof(svp->dram), NULL },
30 { CHUNK_SSP, sizeof(svp->ssp1601) - sizeof(svp->ssp1601.drc), NULL },
35 static void PicoSVPReset(void)
37 elprintf(EL_SVP, "SVP reset");
39 memcpy(svp->iram_rom + 0x800, Pico.rom + 0x800, 0x20000 - 0x800);
40 ssp1601_reset(&svp->ssp1601);
42 if ((PicoOpt&POPT_EN_SVP_DRC) && svp_dyn_ready)
43 ssp1601_dyn_reset(&svp->ssp1601);
48 static void PicoSVPLine(void)
51 #if defined(ARM) || defined(PSP)
53 static int delay_lines = 0;
55 if ((Pico.m.scanline&0xf) != 0xf && Pico.m.scanline != 261 && Pico.m.scanline != 311)
62 if ((PicoOpt&POPT_EN_SVP_DRC) && svp_dyn_ready)
63 ssp1601_dyn_run(PicoSVPCycles * count);
67 ssp1601_run(PicoSVPCycles * count);
68 svp_dyn_ready = 0; // just in case
72 //if (Pico.m.frame_count == 13) PicoPad[0] |= 0xff;
76 static int PicoSVPDma(unsigned int source, int len, unsigned short **srcp, unsigned short **limitp)
78 if (source < Pico.romsize) // Rom
81 *srcp = (unsigned short *)(Pico.rom + (source&~1));
82 *limitp = (unsigned short *)(Pico.rom + Pico.romsize);
85 else if ((source & 0xfe0000) == 0x300000)
87 elprintf(EL_VDPDMA|EL_SVP, "SVP DmaSlow from %06x, len=%i", source, len);
90 *srcp = (unsigned short *)(svp->dram + source);
91 *limitp = (unsigned short *)(svp->dram + sizeof(svp->dram));
95 elprintf(EL_VDPDMA|EL_SVP|EL_ANOMALY, "SVP FIXME unhandled DmaSlow from %06x, len=%i", source, len);
101 void PicoSVPInit(void)
103 #if defined(__linux__) && defined(ARM)
105 ret = munmap(tcache, SSP_DRC_SIZE);
106 printf("munmap tcache: %i\n", ret);
111 static void PicoSVPShutdown(void)
113 #if defined(__linux__) && defined(ARM)
120 void PicoSVPStartup(void)
124 elprintf(EL_STATUS, "SVP startup");
126 tmp = realloc(Pico.rom, 0x200000 + sizeof(*svp));
129 elprintf(EL_STATUS|EL_SVP, "OOM for SVP data");
133 //PicoOpt &= ~0x20000;
135 svp = (void *) ((char *)tmp + 0x200000);
136 memset(svp, 0, sizeof(*svp));
138 #if defined(__linux__) && defined(ARM)
139 tmp = mmap(tcache, SSP_DRC_SIZE, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
140 printf("mmap tcache: %p, asked %p\n", tmp, tcache);
146 if (PicoOpt&POPT_EN_SVP_DRC) {
147 if (ssp1601_dyn_startup()) return;
152 // init ok, setup hooks..
153 PicoCartMemSetup = PicoSVPMemSetup;
154 PicoDmaHook = PicoSVPDma;
155 PicoResetHook = PicoSVPReset;
156 PicoLineHook = PicoSVPLine;
157 PicoCartUnloadHook = PicoSVPShutdown;
160 svp_states[0].ptr = svp->iram_rom;
161 svp_states[1].ptr = svp->dram;
162 svp_states[2].ptr = &svp->ssp1601;
163 carthw_chunks = svp_states;