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"
12 int PicoSVPCycles = 1000; // cycles/line
14 /* save state stuff */
16 CHUNK_IRAM = CHUNK_CARTHW,
21 static carthw_state_chunk svp_states[] =
23 { CHUNK_IRAM, 0x800, NULL },
24 { CHUNK_DRAM, sizeof(svp->dram), NULL },
25 { CHUNK_SSP, sizeof(svp->ssp1601), NULL },
30 static void PicoSVPReset(void)
32 elprintf(EL_SVP, "SVP reset");
34 memcpy(svp->iram_rom + 0x800, Pico.rom + 0x800, 0x20000 - 0x800);
35 ssp1601_reset(&svp->ssp1601);
36 if (!(PicoOpt&0x20000))
37 ssp1601_dyn_reset(&svp->ssp1601);
41 static void PicoSVPLine(int count)
45 ssp1601_run(PicoSVPCycles * count);
47 ssp1601_dyn_run(PicoSVPCycles * count);
50 //if (Pico.m.frame_count == 13) PicoPad[0] |= 0xff;
54 static int PicoSVPDma(unsigned int source, int len, unsigned short **srcp, unsigned short **limitp)
56 if (source < Pico.romsize) // Rom
59 *srcp = (unsigned short *)(Pico.rom + (source&~1));
60 *limitp = (unsigned short *)(Pico.rom + Pico.romsize);
63 else if ((source & 0xfe0000) == 0x300000)
65 elprintf(EL_VDPDMA|EL_SVP, "SVP DmaSlow from %06x, len=%i", source, len);
68 *srcp = (unsigned short *)(svp->dram + source);
69 *limitp = (unsigned short *)(svp->dram + sizeof(svp->dram));
73 elprintf(EL_VDPDMA|EL_SVP|EL_ANOMALY, "SVP FIXME unhandled DmaSlow from %06x, len=%i", source, len);
79 void PicoSVPInit(void)
83 elprintf(EL_SVP, "SVP init");
85 tmp = realloc(Pico.rom, 0x200000 + sizeof(*svp));
88 elprintf(EL_STATUS|EL_SVP, "OOM for SVP data");
93 svp = (void *) ((char *)tmp + 0x200000);
94 memset(svp, 0, sizeof(*svp));
97 if (!(PicoOpt&0x20000)) {
98 if (ssp1601_dyn_init()) return;
101 // init ok, setup hooks..
102 PicoRead16Hook = PicoSVPRead16;
103 PicoWrite8Hook = PicoSVPWrite8;
104 PicoWrite16Hook = PicoSVPWrite16;
105 PicoDmaHook = PicoSVPDma;
106 PicoResetHook = PicoSVPReset;
107 PicoLineHook = PicoSVPLine;
110 svp_states[0].ptr = svp->iram_rom;
111 svp_states[1].ptr = svp->dram;
112 svp_states[2].ptr = &svp->ssp1601;
113 carthw_chunks = svp_states;