svp minor adjustments, copyright
[picodrive.git] / Pico / carthw / svp / svp.c
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
9 #include "../../PicoInt.h"
10
11 svp_t *svp = NULL;
12 int PicoSVPCycles = 800; // cycles/line
13
14 static void PicoSVPReset(void)
15 {
16         elprintf(EL_SVP, "SVP reset");
17
18         memcpy(svp->iram_rom + 0x800, Pico.rom + 0x800, 0x20000 - 0x800);
19         ssp1601_reset(&svp->ssp1601);
20 }
21
22
23 static void PicoSVPLine(int count)
24 {
25         // ???
26         // OSC_NTSC / 3.0 / 60.0 / 262.0 ~= 1139
27         // OSC_PAL  / 3.0 / 50.0 / 312.0 ~= 1137
28         ssp1601_run(PicoSVPCycles * count);
29
30         // test mode
31         //if (Pico.m.frame_count == 13) PicoPad[0] |= 0xff;
32 }
33
34
35 static int PicoSVPDma(unsigned int source, int len, unsigned short **srcp, unsigned short **limitp)
36 {
37         if (source < Pico.romsize) // Rom
38         {
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)
45         {
46                 elprintf(EL_VDPDMA|EL_SVP, "SVP DmaSlow from %06x, len=%i", source, len);
47                 source &= 0x1fffe;
48                 source -= 2;
49                 *srcp = (unsigned short *)(svp->dram + source);
50                 *limitp = (unsigned short *)(svp->dram + sizeof(svp->dram));
51                 return 1;
52         }
53         else
54                 elprintf(EL_VDPDMA|EL_SVP|EL_ANOMALY, "SVP FIXME unhandled DmaSlow from %06x, len=%i", source, len);
55
56         return 0;
57 }
58
59
60 void PicoSVPInit(void)
61 {
62         void *tmp;
63
64         elprintf(EL_SVP, "SVP init");
65
66         tmp = realloc(Pico.rom, 0x200000 + sizeof(*svp));
67         if (tmp == NULL)
68         {
69                 elprintf(EL_STATUS|EL_SVP, "OOM for SVP data");
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;
82         PicoResetHook = PicoSVPReset;
83         PicoLineHook = PicoSVPLine;
84 }
85