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 = 1000; // cycles/line
18 /* save state stuff */
20 CHUNK_IRAM = CHUNK_CARTHW,
25 static carthw_state_chunk svp_states[] =
27 { CHUNK_IRAM, 0x800, NULL },
28 { CHUNK_DRAM, sizeof(svp->dram), NULL },
29 { CHUNK_SSP, sizeof(svp->ssp1601) - sizeof(svp->ssp1601.drc), NULL },
34 static void PicoSVPReset(void)
36 elprintf(EL_SVP, "SVP reset");
38 memcpy(svp->iram_rom + 0x800, Pico.rom + 0x800, 0x20000 - 0x800);
39 ssp1601_reset(&svp->ssp1601);
40 if (!(PicoOpt&0x20000))
41 ssp1601_dyn_reset(&svp->ssp1601);
45 static void PicoSVPLine(int count)
48 ssp1601_run(PicoSVPCycles * count);
50 ssp1601_dyn_run(PicoSVPCycles * count);
53 //if (Pico.m.frame_count == 13) PicoPad[0] |= 0xff;
57 static int PicoSVPDma(unsigned int source, int len, unsigned short **srcp, unsigned short **limitp)
59 if (source < Pico.romsize) // Rom
62 *srcp = (unsigned short *)(Pico.rom + (source&~1));
63 *limitp = (unsigned short *)(Pico.rom + Pico.romsize);
66 else if ((source & 0xfe0000) == 0x300000)
68 elprintf(EL_VDPDMA|EL_SVP, "SVP DmaSlow from %06x, len=%i", source, len);
71 *srcp = (unsigned short *)(svp->dram + source);
72 *limitp = (unsigned short *)(svp->dram + sizeof(svp->dram));
76 elprintf(EL_VDPDMA|EL_SVP|EL_ANOMALY, "SVP FIXME unhandled DmaSlow from %06x, len=%i", source, len);
82 void PicoSVPInit(void)
86 ret = munmap(tcache, TCACHE_SIZE);
87 printf("munmap tcache: %i\n", ret);
92 static void PicoSVPShutdown(void)
101 void PicoSVPStartup(void)
105 elprintf(EL_SVP, "SVP init");
107 tmp = realloc(Pico.rom, 0x200000 + sizeof(*svp));
110 elprintf(EL_STATUS|EL_SVP, "OOM for SVP data");
114 //PicoOpt |= 0x20000;
116 svp = (void *) ((char *)tmp + 0x200000);
117 memset(svp, 0, sizeof(*svp));
120 tmp = mmap(tcache, TCACHE_SIZE, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
121 printf("mmap tcache: %p, asked %p\n", tmp, tcache);
125 if (!(PicoOpt&0x20000)) {
126 if (ssp1601_dyn_startup()) return;
129 // init ok, setup hooks..
130 PicoRead16Hook = PicoSVPRead16;
131 PicoWrite8Hook = PicoSVPWrite8;
132 PicoWrite16Hook = PicoSVPWrite16;
133 PicoDmaHook = PicoSVPDma;
134 PicoResetHook = PicoSVPReset;
135 PicoLineHook = PicoSVPLine;
136 PicoCartUnloadHook = PicoSVPShutdown;
139 svp_states[0].ptr = svp->iram_rom;
140 svp_states[1].ptr = svp->dram;
141 svp_states[2].ptr = &svp->ssp1601;
142 carthw_chunks = svp_states;