2 * The SVP chip emulator, mem I/O stuff
4 * Copyright (c) GraÅžvydas "notaz" Ignotas, 2008
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the organization nor the
14 * names of its contributors may be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "../../pico_int.h"
30 #include "../../memory.h"
33 static void PicoWrite16_dram(u32 a, u32 d)
38 if (a == 0xfe06) // 30fe06
39 svp->ssp1601.emu_status &= ~SSP_WAIT_30FE06;
41 svp->ssp1601.emu_status &= ~SSP_WAIT_30FE08;
44 ((u16 *)svp->dram)[a / 2] = d;
47 // "cell arrange" 1: 390000-39ffff
48 static u32 PicoRead16_svpca1(u32 a)
50 // this is 68k code rewritten
52 a1 = (a1 & 0x7001) | ((a1 & 0x3e) << 6) | ((a1 & 0xfc0) >> 5);
53 return ((u16 *)svp->dram)[a1];
56 // "cell arrange" 2: 3a0000-3affff
57 static u32 PicoRead16_svpca2(u32 a)
60 a1 = (a1 & 0x7801) | ((a1 & 0x1e) << 6) | ((a1 & 0x7e0) >> 4);
61 return ((u16 *)svp->dram)[a1];
64 // IO/control area (0xa10000 - 0xa1ffff)
65 static u32 PicoRead16_svpr(u32 a)
70 if ((a & ~0x0f) == 0xa15000) {
74 d = svp->ssp1601.gr[SSP_XST].h;
78 d = svp->ssp1601.gr[SSP_PM0].h;
79 svp->ssp1601.gr[SSP_PM0].h &= ~1;
83 #if EL_LOGMASK & EL_SVP
85 static int a15004_looping = 0;
86 if (a == 0xa15004 && (d & 1))
90 elprintf(EL_SVP, "SVP r%i: [%06x] %04x @%06x", realsize, a, d, SekPc);
92 if (a == 0xa15004 && !(d&1)) {
94 elprintf(EL_SVP, "SVP det TIGHT loop: a15004");
104 //if (a == 0x30fe02 && d == 0)
105 // elprintf(EL_ANOMALY, "SVP lag?");
107 return PicoRead16_io(a);
110 // used in VR test mode
111 static u32 PicoRead8_svpr(u32 a)
115 if ((a & ~0x0f) != 0xa15000)
116 return PicoRead8_io(a);
118 d = PicoRead16_svpr(a & ~1);
124 static void PicoWrite16_svpr(u32 a, u32 d)
126 elprintf(EL_SVP, "SVP w16: [%06x] %04x @%06x", a, d, SekPc);
128 if ((a & ~0x0f) == 0xa15000) {
129 if (a == 0xa15000 || a == 0xa15002) {
130 // just guessing here
131 svp->ssp1601.gr[SSP_XST].h = d;
132 svp->ssp1601.gr[SSP_PM0].h |= 2;
133 svp->ssp1601.emu_status &= ~SSP_WAIT_PM0;
135 //else if (a == 0xa15006) svp->ssp1601.gr[SSP_PM0].h = d | (d << 1);
136 // 0xa15006 probably has 'halt'
140 PicoWrite16_io(a, d);
143 void PicoSVPMemSetup(void)
147 cpu68k_map_set(m68k_read8_map, 0x300000, 0x31ffff, svp->dram, 0);
148 cpu68k_map_set(m68k_read16_map, 0x300000, 0x31ffff, svp->dram, 0);
149 cpu68k_map_set(m68k_write8_map, 0x300000, 0x31ffff, svp->dram, 0);
150 cpu68k_map_set(m68k_write16_map, 0x300000, 0x31ffff, svp->dram, 0);
151 cpu68k_map_set(m68k_write16_map, 0x300000, 0x30ffff, PicoWrite16_dram, 1);
153 // DRAM (cell arrange)
154 cpu68k_map_set(m68k_read16_map, 0x390000, 0x39ffff, PicoRead16_svpca1, 1);
155 cpu68k_map_set(m68k_read16_map, 0x3a0000, 0x3affff, PicoRead16_svpca2, 1);
158 cpu68k_map_set(m68k_read8_map, 0xa10000, 0xa1ffff, PicoRead8_svpr, 1);
159 cpu68k_map_set(m68k_read16_map, 0xa10000, 0xa1ffff, PicoRead16_svpr, 1);
160 cpu68k_map_set(m68k_write8_map, 0xa10000, 0xa1ffff, PicoWrite8_io, 1); // PicoWrite8_svpr
161 cpu68k_map_set(m68k_write16_map, 0xa10000, 0xa1ffff, PicoWrite16_svpr, 1);