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