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 |
11 | svp_t *svp = NULL; |
16ebbe9e |
12 | int PicoSVPCycles = 1000; // cycles/line |
f8ef8ff7 |
13 | |
017512f2 |
14 | static 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 |
23 | static void PicoSVPLine(int count) |
017512f2 |
24 | { |
25 | // ??? |
0ffefdb8 |
26 | ssp1601_run(PicoSVPCycles * count); |
d26dc685 |
27 | |
28 | // test mode |
29 | //if (Pico.m.frame_count == 13) PicoPad[0] |= 0xff; |
017512f2 |
30 | } |
31 | |
32 | |
5de27868 |
33 | static int PicoSVPDma(unsigned int source, int len, unsigned short **srcp, unsigned short **limitp) |
017512f2 |
34 | { |
d4ca252d |
35 | if (source < Pico.romsize) // Rom |
36 | { |
50483b53 |
37 | source -= 2; |
38 | *srcp = (unsigned short *)(Pico.rom + (source&~1)); |
39 | *limitp = (unsigned short *)(Pico.rom + Pico.romsize); |
40 | return 1; |
41 | } |
42 | else if ((source & 0xfe0000) == 0x300000) |
017512f2 |
43 | { |
5de27868 |
44 | elprintf(EL_VDPDMA|EL_SVP, "SVP DmaSlow from %06x, len=%i", source, len); |
017512f2 |
45 | source &= 0x1fffe; |
30752975 |
46 | source -= 2; |
5de27868 |
47 | *srcp = (unsigned short *)(svp->dram + source); |
48 | *limitp = (unsigned short *)(svp->dram + sizeof(svp->dram)); |
017512f2 |
49 | return 1; |
50 | } |
d26dc685 |
51 | else |
52 | elprintf(EL_VDPDMA|EL_SVP|EL_ANOMALY, "SVP FIXME unhandled DmaSlow from %06x, len=%i", source, len); |
017512f2 |
53 | |
54 | return 0; |
55 | } |
56 | |
57 | |
f53f286a |
58 | void PicoSVPInit(void) |
59 | { |
f8ef8ff7 |
60 | void *tmp; |
61 | |
017512f2 |
62 | elprintf(EL_SVP, "SVP init"); |
f8ef8ff7 |
63 | |
64 | tmp = realloc(Pico.rom, 0x200000 + sizeof(*svp)); |
65 | if (tmp == NULL) |
66 | { |
017512f2 |
67 | elprintf(EL_STATUS|EL_SVP, "OOM for SVP data"); |
f8ef8ff7 |
68 | return; |
69 | } |
70 | |
71 | Pico.rom = tmp; |
72 | svp = (void *) ((char *)tmp + 0x200000); |
73 | memset(svp, 0, sizeof(*svp)); |
74 | |
75 | // init ok, setup hooks.. |
76 | PicoRead16Hook = PicoSVPRead16; |
77 | PicoWrite8Hook = PicoSVPWrite8; |
78 | PicoWrite16Hook = PicoSVPWrite16; |
79 | PicoDmaHook = PicoSVPDma; |
017512f2 |
80 | PicoResetHook = PicoSVPReset; |
81 | PicoLineHook = PicoSVPLine; |
f53f286a |
82 | } |
83 | |