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