32x: split sh2 code, compiler stub
[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
efcba75f 9#include "../../pico_int.h"
e807ac75 10#include "compiler.h"
f53f286a 11
f8ef8ff7 12svp_t *svp = NULL;
3d48ce71 13int PicoSVPCycles = 850; // cycles/line, just a guess
1ca2ea4f 14static int svp_dyn_ready = 0;
f8ef8ff7 15
945c2fdc 16/* save state stuff */
17typedef enum {
18 CHUNK_IRAM = CHUNK_CARTHW,
19 CHUNK_DRAM,
20 CHUNK_SSP
21} chunk_name_e;
22
23static carthw_state_chunk svp_states[] =
24{
25 { CHUNK_IRAM, 0x800, NULL },
26 { CHUNK_DRAM, sizeof(svp->dram), NULL },
e122fae6 27 { CHUNK_SSP, sizeof(svp->ssp1601) - sizeof(svp->ssp1601.drc), NULL },
945c2fdc 28 { 0, 0, NULL }
29};
30
31
017512f2 32static void PicoSVPReset(void)
33{
34 elprintf(EL_SVP, "SVP reset");
35
5de27868 36 memcpy(svp->iram_rom + 0x800, Pico.rom + 0x800, 0x20000 - 0x800);
017512f2 37 ssp1601_reset(&svp->ssp1601);
6fc57144 38#ifndef PSP
602133e1 39 if ((PicoOpt&POPT_EN_SVP_DRC) && svp_dyn_ready)
726bbb3e 40 ssp1601_dyn_reset(&svp->ssp1601);
6fc57144 41#endif
017512f2 42}
43
44
e7aac062 45static void PicoSVPLine(void)
017512f2 46{
e7aac062 47 int count = 1;
48#if defined(ARM) || defined(PSP)
49 // performance hack
50 static int delay_lines = 0;
51 delay_lines++;
52 if ((Pico.m.scanline&0xf) != 0xf && Pico.m.scanline != 261 && Pico.m.scanline != 311)
53 return;
54 count = delay_lines;
55 delay_lines = 0;
56#endif
57
6fc57144 58#ifndef PSP
602133e1 59 if ((PicoOpt&POPT_EN_SVP_DRC) && svp_dyn_ready)
726bbb3e 60 ssp1601_dyn_run(PicoSVPCycles * count);
6fc57144 61 else
62#endif
63 {
1ca2ea4f 64 ssp1601_run(PicoSVPCycles * count);
1b13dae0 65 svp_dyn_ready = 0; // just in case
66 }
d26dc685 67
68 // test mode
69 //if (Pico.m.frame_count == 13) PicoPad[0] |= 0xff;
017512f2 70}
71
72
5de27868 73static int PicoSVPDma(unsigned int source, int len, unsigned short **srcp, unsigned short **limitp)
017512f2 74{
d4ca252d 75 if (source < Pico.romsize) // Rom
76 {
50483b53 77 source -= 2;
78 *srcp = (unsigned short *)(Pico.rom + (source&~1));
79 *limitp = (unsigned short *)(Pico.rom + Pico.romsize);
80 return 1;
81 }
82 else if ((source & 0xfe0000) == 0x300000)
017512f2 83 {
5de27868 84 elprintf(EL_VDPDMA|EL_SVP, "SVP DmaSlow from %06x, len=%i", source, len);
017512f2 85 source &= 0x1fffe;
30752975 86 source -= 2;
5de27868 87 *srcp = (unsigned short *)(svp->dram + source);
88 *limitp = (unsigned short *)(svp->dram + sizeof(svp->dram));
017512f2 89 return 1;
90 }
d26dc685 91 else
92 elprintf(EL_VDPDMA|EL_SVP|EL_ANOMALY, "SVP FIXME unhandled DmaSlow from %06x, len=%i", source, len);
017512f2 93
94 return 0;
95}
96
97
f53f286a 98void PicoSVPInit(void)
e807ac75 99{
e807ac75 100}
101
102
103void PicoSVPStartup(void)
f53f286a 104{
f8ef8ff7 105 void *tmp;
106
45f2f245 107 elprintf(EL_STATUS, "SVP startup");
f8ef8ff7 108
109 tmp = realloc(Pico.rom, 0x200000 + sizeof(*svp));
110 if (tmp == NULL)
111 {
017512f2 112 elprintf(EL_STATUS|EL_SVP, "OOM for SVP data");
f8ef8ff7 113 return;
114 }
115
1ca2ea4f 116 //PicoOpt &= ~0x20000;
f8ef8ff7 117 Pico.rom = tmp;
118 svp = (void *) ((char *)tmp + 0x200000);
119 memset(svp, 0, sizeof(*svp));
120
726bbb3e 121 // init SVP compiler
1ca2ea4f 122 svp_dyn_ready = 0;
6fc57144 123#ifndef PSP
41397701 124 if (PicoOpt & POPT_EN_SVP_DRC) {
125 if (ssp1601_dyn_startup())
126 return;
1ca2ea4f 127 svp_dyn_ready = 1;
726bbb3e 128 }
6fc57144 129#endif
726bbb3e 130
f8ef8ff7 131 // init ok, setup hooks..
45f2f245 132 PicoCartMemSetup = PicoSVPMemSetup;
f8ef8ff7 133 PicoDmaHook = PicoSVPDma;
017512f2 134 PicoResetHook = PicoSVPReset;
135 PicoLineHook = PicoSVPLine;
945c2fdc 136
137 // save state stuff
138 svp_states[0].ptr = svp->iram_rom;
139 svp_states[1].ptr = svp->dram;
140 svp_states[2].ptr = &svp->ssp1601;
141 carthw_chunks = svp_states;
602133e1 142 PicoAHW |= PAHW_SVP;
f53f286a 143}
144
e807ac75 145