svp compiler, early stage, works
[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;
16ebbe9e 12int PicoSVPCycles = 1000; // cycles/line
f8ef8ff7 13
945c2fdc 14/* save state stuff */
15typedef enum {
16 CHUNK_IRAM = CHUNK_CARTHW,
17 CHUNK_DRAM,
18 CHUNK_SSP
19} chunk_name_e;
20
21static carthw_state_chunk svp_states[] =
22{
23 { CHUNK_IRAM, 0x800, NULL },
24 { CHUNK_DRAM, sizeof(svp->dram), NULL },
25 { CHUNK_SSP, sizeof(svp->ssp1601), NULL },
26 { 0, 0, NULL }
27};
28
29
017512f2 30static void PicoSVPReset(void)
31{
32 elprintf(EL_SVP, "SVP reset");
33
5de27868 34 memcpy(svp->iram_rom + 0x800, Pico.rom + 0x800, 0x20000 - 0x800);
017512f2 35 ssp1601_reset(&svp->ssp1601);
726bbb3e 36 if (!(PicoOpt&0x20000))
37 ssp1601_dyn_reset(&svp->ssp1601);
017512f2 38}
39
40
0ffefdb8 41static void PicoSVPLine(int count)
017512f2 42{
43 // ???
726bbb3e 44 if (PicoOpt&0x20000)
45 ssp1601_run(PicoSVPCycles * count);
46 else
47 ssp1601_dyn_run(PicoSVPCycles * count);
d26dc685 48
49 // test mode
50 //if (Pico.m.frame_count == 13) PicoPad[0] |= 0xff;
017512f2 51}
52
53
5de27868 54static int PicoSVPDma(unsigned int source, int len, unsigned short **srcp, unsigned short **limitp)
017512f2 55{
d4ca252d 56 if (source < Pico.romsize) // Rom
57 {
50483b53 58 source -= 2;
59 *srcp = (unsigned short *)(Pico.rom + (source&~1));
60 *limitp = (unsigned short *)(Pico.rom + Pico.romsize);
61 return 1;
62 }
63 else if ((source & 0xfe0000) == 0x300000)
017512f2 64 {
5de27868 65 elprintf(EL_VDPDMA|EL_SVP, "SVP DmaSlow from %06x, len=%i", source, len);
017512f2 66 source &= 0x1fffe;
30752975 67 source -= 2;
5de27868 68 *srcp = (unsigned short *)(svp->dram + source);
69 *limitp = (unsigned short *)(svp->dram + sizeof(svp->dram));
017512f2 70 return 1;
71 }
d26dc685 72 else
73 elprintf(EL_VDPDMA|EL_SVP|EL_ANOMALY, "SVP FIXME unhandled DmaSlow from %06x, len=%i", source, len);
017512f2 74
75 return 0;
76}
77
78
f53f286a 79void PicoSVPInit(void)
80{
f8ef8ff7 81 void *tmp;
82
017512f2 83 elprintf(EL_SVP, "SVP init");
f8ef8ff7 84
85 tmp = realloc(Pico.rom, 0x200000 + sizeof(*svp));
86 if (tmp == NULL)
87 {
017512f2 88 elprintf(EL_STATUS|EL_SVP, "OOM for SVP data");
f8ef8ff7 89 return;
90 }
91
92 Pico.rom = tmp;
93 svp = (void *) ((char *)tmp + 0x200000);
94 memset(svp, 0, sizeof(*svp));
95
726bbb3e 96 // init SVP compiler
97 if (!(PicoOpt&0x20000)) {
98 if (ssp1601_dyn_init()) return;
99 }
100
f8ef8ff7 101 // init ok, setup hooks..
102 PicoRead16Hook = PicoSVPRead16;
103 PicoWrite8Hook = PicoSVPWrite8;
104 PicoWrite16Hook = PicoSVPWrite16;
105 PicoDmaHook = PicoSVPDma;
017512f2 106 PicoResetHook = PicoSVPReset;
107 PicoLineHook = PicoSVPLine;
945c2fdc 108
109 // save state stuff
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;
f53f286a 114}
115