fix various logging issues
[picodrive.git] / pico / carthw / svp / memory.c
CommitLineData
cff531af 1/*
2 * The SVP chip emulator, mem I/O stuff
3 *
4 * Copyright (c) GraÅžvydas "notaz" Ignotas, 2008
5 *
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.
16 *
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.
27 */
d4ca252d 28
efcba75f 29#include "../../pico_int.h"
45f2f245 30#include "../../memory.h"
f53f286a 31
72f63cf0 32// for wait loop det
33static void PicoWrite16_dram(u32 a, u32 d)
34{
35 a &= ~0xfe0000;
d26dc685 36
72f63cf0 37 if (d != 0) {
38 if (a == 0xfe06) // 30fe06
39 svp->ssp1601.emu_status &= ~SSP_WAIT_30FE06;
40 else if (a == 0xfe08)
41 svp->ssp1601.emu_status &= ~SSP_WAIT_30FE08;
d26dc685 42 }
72f63cf0 43
44 ((u16 *)svp->dram)[a / 2] = d;
45}
46
47// "cell arrange" 1: 390000-39ffff
48static u32 PicoRead16_svpca1(u32 a)
49{
50 // this is 68k code rewritten
51 u32 a1 = a >> 1;
52 a1 = (a1 & 0x7001) | ((a1 & 0x3e) << 6) | ((a1 & 0xfc0) >> 5);
53 return ((u16 *)svp->dram)[a1];
54}
55
56// "cell arrange" 2: 3a0000-3affff
57static u32 PicoRead16_svpca2(u32 a)
58{
59 u32 a1 = a >> 1;
60 a1 = (a1 & 0x7801) | ((a1 & 0x1e) << 6) | ((a1 & 0x7e0) >> 4);
61 return ((u16 *)svp->dram)[a1];
62}
45f2f245 63
64// IO/control area (0xa10000 - 0xa1ffff)
65static u32 PicoRead16_svpr(u32 a)
66{
67 u32 d = 0;
d26dc685 68
69 // regs
72f63cf0 70 if ((a & ~0x0f) == 0xa15000) {
d26dc685 71 switch (a & 0xf) {
72 case 0:
73 case 2:
74 d = svp->ssp1601.gr[SSP_XST].h;
75 break;
76
77 case 4:
78 d = svp->ssp1601.gr[SSP_PM0].h;
79 svp->ssp1601.gr[SSP_PM0].h &= ~1;
d26dc685 80 break;
81 }
d26dc685 82
45f2f245 83#if EL_LOGMASK & EL_SVP
84 {
85 static int a15004_looping = 0;
86 if (a == 0xa15004 && (d & 1))
87 a15004_looping = 0;
88
89 if (!a15004_looping)
ebd70cb5 90 elprintf(EL_SVP, "SVP r: [%06x] %04x @%06x", a, d, SekPc);
45f2f245 91
92 if (a == 0xa15004 && !(d&1)) {
93 if (!a15004_looping)
94 elprintf(EL_SVP, "SVP det TIGHT loop: a15004");
95 a15004_looping = 1;
96 }
97 else
98 a15004_looping = 0;
99 }
100#endif
101 return d;
d26dc685 102 }
f53f286a 103
16ebbe9e 104 //if (a == 0x30fe02 && d == 0)
105 // elprintf(EL_ANOMALY, "SVP lag?");
f8ef8ff7 106
45f2f245 107 return PicoRead16_io(a);
f53f286a 108}
109
72f63cf0 110// used in VR test mode
111static u32 PicoRead8_svpr(u32 a)
112{
113 u32 d;
114
115 if ((a & ~0x0f) != 0xa15000)
116 return PicoRead8_io(a);
117
118 d = PicoRead16_svpr(a & ~1);
119 if (!(a & 1))
120 d >>= 8;
121 return d;
122}
123
45f2f245 124static void PicoWrite16_svpr(u32 a, u32 d)
f53f286a 125{
45f2f245 126 elprintf(EL_SVP, "SVP w16: [%06x] %04x @%06x", a, d, SekPc);
f8ef8ff7 127
72f63cf0 128 if ((a & ~0x0f) == 0xa15000) {
d26dc685 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;
134 }
135 //else if (a == 0xa15006) svp->ssp1601.gr[SSP_PM0].h = d | (d << 1);
136 // 0xa15006 probably has 'halt'
45f2f245 137 return;
d26dc685 138 }
d26dc685 139
45f2f245 140 PicoWrite16_io(a, d);
45f2f245 141}
142
143void PicoSVPMemSetup(void)
144{
145 // 68k memmap:
146 // DRAM
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);
72f63cf0 151 cpu68k_map_set(m68k_write16_map, 0x300000, 0x30ffff, PicoWrite16_dram, 1);
30752975 152
72f63cf0 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);
f8ef8ff7 156
45f2f245 157 // regs
72f63cf0 158 cpu68k_map_set(m68k_read8_map, 0xa10000, 0xa1ffff, PicoRead8_svpr, 1);
45f2f245 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);
f53f286a 162}
163