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);
41 if ((PicoOpt&0x20000) && svp_dyn_ready)
42 ssp1601_dyn_reset(&svp->ssp1601);
46 static void PicoSVPLine(int count)
48 if ((PicoOpt&0x20000) && svp_dyn_ready)
49 ssp1601_dyn_run(PicoSVPCycles * count);
51 ssp1601_run(PicoSVPCycles * count);
52 svp_dyn_ready = 0; // just in case
56 //if (Pico.m.frame_count == 13) PicoPad[0] |= 0xff;
60 static int PicoSVPDma(unsigned int source, int len, unsigned short **srcp, unsigned short **limitp)
62 if (source < Pico.romsize) // Rom
65 *srcp = (unsigned short *)(Pico.rom + (source&~1));
66 *limitp = (unsigned short *)(Pico.rom + Pico.romsize);
69 else if ((source & 0xfe0000) == 0x300000)
71 elprintf(EL_VDPDMA|EL_SVP, "SVP DmaSlow from %06x, len=%i", source, len);
74 *srcp = (unsigned short *)(svp->dram + source);
75 *limitp = (unsigned short *)(svp->dram + sizeof(svp->dram));
79 elprintf(EL_VDPDMA|EL_SVP|EL_ANOMALY, "SVP FIXME unhandled DmaSlow from %06x, len=%i", source, len);
85 void PicoSVPInit(void)
89 ret = munmap(tcache, SSP_DRC_SIZE);
90 printf("munmap tcache: %i\n", ret);
95 static void PicoSVPShutdown(void)
104 void PicoSVPStartup(void)
108 elprintf(EL_SVP, "SVP init");
110 tmp = realloc(Pico.rom, 0x200000 + sizeof(*svp));
113 elprintf(EL_STATUS|EL_SVP, "OOM for SVP data");
117 //PicoOpt &= ~0x20000;
119 svp = (void *) ((char *)tmp + 0x200000);
120 memset(svp, 0, sizeof(*svp));
123 tmp = mmap(tcache, SSP_DRC_SIZE, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
124 printf("mmap tcache: %p, asked %p\n", tmp, tcache);
129 if (PicoOpt&0x20000) {
130 if (ssp1601_dyn_startup()) return;
134 // init ok, setup hooks..
135 PicoRead16Hook = PicoSVPRead16;
136 PicoWrite8Hook = PicoSVPWrite8;
137 PicoWrite16Hook = PicoSVPWrite16;
138 PicoDmaHook = PicoSVPDma;
139 PicoResetHook = PicoSVPReset;
140 PicoLineHook = PicoSVPLine;
141 PicoCartUnloadHook = PicoSVPShutdown;
144 svp_states[0].ptr = svp->iram_rom;
145 svp_states[1].ptr = svp->dram;
146 svp_states[2].ptr = &svp->ssp1601;
147 carthw_chunks = svp_states;