bugfixes
[picodrive.git] / Pico / carthw / svp / svp.c
CommitLineData
d4ca252d 1// The SVP chip emulator
2
3// (c) Copyright 2008, Grazvydas "notaz" Ignotas
4// Free for non-commercial use.
5
6// For commercial use, separate licencing terms must be obtained.
7
8
f53f286a 9#include "../../PicoInt.h"
10
f8ef8ff7 11svp_t *svp = NULL;
0ffefdb8 12int PicoSVPCycles = 800; // cycles/line
f8ef8ff7 13
017512f2 14static void PicoSVPReset(void)
15{
16 elprintf(EL_SVP, "SVP reset");
17
5de27868 18 memcpy(svp->iram_rom + 0x800, Pico.rom + 0x800, 0x20000 - 0x800);
017512f2 19 ssp1601_reset(&svp->ssp1601);
20}
21
22
0ffefdb8 23static void PicoSVPLine(int count)
017512f2 24{
25 // ???
26 // OSC_NTSC / 3.0 / 60.0 / 262.0 ~= 1139
27 // OSC_PAL / 3.0 / 50.0 / 312.0 ~= 1137
0ffefdb8 28 ssp1601_run(PicoSVPCycles * count);
d26dc685 29
30 // test mode
31 //if (Pico.m.frame_count == 13) PicoPad[0] |= 0xff;
017512f2 32}
33
34
5de27868 35static int PicoSVPDma(unsigned int source, int len, unsigned short **srcp, unsigned short **limitp)
017512f2 36{
d4ca252d 37 if (source < Pico.romsize) // Rom
38 {
50483b53 39 source -= 2;
40 *srcp = (unsigned short *)(Pico.rom + (source&~1));
41 *limitp = (unsigned short *)(Pico.rom + Pico.romsize);
42 return 1;
43 }
44 else if ((source & 0xfe0000) == 0x300000)
017512f2 45 {
5de27868 46 elprintf(EL_VDPDMA|EL_SVP, "SVP DmaSlow from %06x, len=%i", source, len);
017512f2 47 source &= 0x1fffe;
30752975 48 source -= 2;
5de27868 49 *srcp = (unsigned short *)(svp->dram + source);
50 *limitp = (unsigned short *)(svp->dram + sizeof(svp->dram));
017512f2 51 return 1;
52 }
d26dc685 53 else
54 elprintf(EL_VDPDMA|EL_SVP|EL_ANOMALY, "SVP FIXME unhandled DmaSlow from %06x, len=%i", source, len);
017512f2 55
56 return 0;
57}
58
59
f53f286a 60void PicoSVPInit(void)
61{
f8ef8ff7 62 void *tmp;
63
017512f2 64 elprintf(EL_SVP, "SVP init");
f8ef8ff7 65
66 tmp = realloc(Pico.rom, 0x200000 + sizeof(*svp));
67 if (tmp == NULL)
68 {
017512f2 69 elprintf(EL_STATUS|EL_SVP, "OOM for SVP data");
f8ef8ff7 70 return;
71 }
72
73 Pico.rom = tmp;
74 svp = (void *) ((char *)tmp + 0x200000);
75 memset(svp, 0, sizeof(*svp));
76
77 // init ok, setup hooks..
78 PicoRead16Hook = PicoSVPRead16;
79 PicoWrite8Hook = PicoSVPWrite8;
80 PicoWrite16Hook = PicoSVPWrite16;
81 PicoDmaHook = PicoSVPDma;
017512f2 82 PicoResetHook = PicoSVPReset;
83 PicoLineHook = PicoSVPLine;
f53f286a 84}
85