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), 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)
47 static int inited = 0;
48 if (!(svp->ssp1601.gr[SSP_PM0].h & 2) && !inited) return;
53 ssp1601_run(PicoSVPCycles * count);
55 ssp1601_dyn_run(PicoSVPCycles * count);
58 //if (Pico.m.frame_count == 13) PicoPad[0] |= 0xff;
62 static int PicoSVPDma(unsigned int source, int len, unsigned short **srcp, unsigned short **limitp)
64 if (source < Pico.romsize) // Rom
67 *srcp = (unsigned short *)(Pico.rom + (source&~1));
68 *limitp = (unsigned short *)(Pico.rom + Pico.romsize);
71 else if ((source & 0xfe0000) == 0x300000)
73 elprintf(EL_VDPDMA|EL_SVP, "SVP DmaSlow from %06x, len=%i", source, len);
76 *srcp = (unsigned short *)(svp->dram + source);
77 *limitp = (unsigned short *)(svp->dram + sizeof(svp->dram));
81 elprintf(EL_VDPDMA|EL_SVP|EL_ANOMALY, "SVP FIXME unhandled DmaSlow from %06x, len=%i", source, len);
87 void PicoSVPInit(void)
91 ret = munmap(tcache, TCACHE_SIZE);
92 printf("munmap tcache: %i\n", ret);
97 static void PicoSVPShutdown(void)
106 void PicoSVPStartup(void)
110 elprintf(EL_SVP, "SVP init");
112 tmp = realloc(Pico.rom, 0x200000 + sizeof(*svp));
115 elprintf(EL_STATUS|EL_SVP, "OOM for SVP data");
120 svp = (void *) ((char *)tmp + 0x200000);
121 memset(svp, 0, sizeof(*svp));
124 tmp = mmap(tcache, TCACHE_SIZE, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
125 printf("mmap tcache: %p, asked %p\n", tmp, tcache);
129 if (!(PicoOpt&0x20000)) {
130 if (ssp1601_dyn_startup()) return;
133 // init ok, setup hooks..
134 PicoRead16Hook = PicoSVPRead16;
135 PicoWrite8Hook = PicoSVPWrite8;
136 PicoWrite16Hook = PicoSVPWrite16;
137 PicoDmaHook = PicoSVPDma;
138 PicoResetHook = PicoSVPReset;
139 PicoLineHook = PicoSVPLine;
140 PicoCartUnloadHook = PicoSVPShutdown;
143 svp_states[0].ptr = svp->iram_rom;
144 svp_states[1].ptr = svp->dram;
145 svp_states[2].ptr = &svp->ssp1601;
146 carthw_chunks = svp_states;