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 "../../PicoInt.h"
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(int count)
51 if ((PicoOpt&POPT_EN_SVP_DRC) && svp_dyn_ready)
52 ssp1601_dyn_run(PicoSVPCycles * count);
56 ssp1601_run(PicoSVPCycles * count);
57 svp_dyn_ready = 0; // just in case
61 //if (Pico.m.frame_count == 13) PicoPad[0] |= 0xff;
65 static int PicoSVPDma(unsigned int source, int len, unsigned short **srcp, unsigned short **limitp)
67 if (source < Pico.romsize) // Rom
70 *srcp = (unsigned short *)(Pico.rom + (source&~1));
71 *limitp = (unsigned short *)(Pico.rom + Pico.romsize);
74 else if ((source & 0xfe0000) == 0x300000)
76 elprintf(EL_VDPDMA|EL_SVP, "SVP DmaSlow from %06x, len=%i", source, len);
79 *srcp = (unsigned short *)(svp->dram + source);
80 *limitp = (unsigned short *)(svp->dram + sizeof(svp->dram));
84 elprintf(EL_VDPDMA|EL_SVP|EL_ANOMALY, "SVP FIXME unhandled DmaSlow from %06x, len=%i", source, len);
90 void PicoSVPInit(void)
94 ret = munmap(tcache, SSP_DRC_SIZE);
95 printf("munmap tcache: %i\n", ret);
100 static void PicoSVPShutdown(void)
109 void PicoSVPStartup(void)
113 elprintf(EL_SVP, "SVP init");
115 tmp = realloc(Pico.rom, 0x200000 + sizeof(*svp));
118 elprintf(EL_STATUS|EL_SVP, "OOM for SVP data");
122 //PicoOpt &= ~0x20000;
124 svp = (void *) ((char *)tmp + 0x200000);
125 memset(svp, 0, sizeof(*svp));
128 tmp = mmap(tcache, SSP_DRC_SIZE, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
129 printf("mmap tcache: %p, asked %p\n", tmp, tcache);
135 if (PicoOpt&POPT_EN_SVP_DRC) {
136 if (ssp1601_dyn_startup()) return;
141 // init ok, setup hooks..
142 PicoRead16Hook = PicoSVPRead16;
143 PicoWrite8Hook = PicoSVPWrite8;
144 PicoWrite16Hook = PicoSVPWrite16;
145 PicoDmaHook = PicoSVPDma;
146 PicoResetHook = PicoSVPReset;
147 PicoLineHook = PicoSVPLine;
148 PicoCartUnloadHook = PicoSVPShutdown;
151 svp_states[0].ptr = svp->iram_rom;
152 svp_states[1].ptr = svp->dram;
153 svp_states[2].ptr = &svp->ssp1601;
154 carthw_chunks = svp_states;