32x: some missed code from MAME, minor tweaks
[picodrive.git] / pico / carthw / svp / memory.c
CommitLineData
65ca3034 1// The SVP chip emulator, mem I/O stuff
d4ca252d 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"
45f2f245 10#include "../../memory.h"
f53f286a 11
45f2f245 12/*
d26dc685 13 // "cell arrange" 1: 390000-39ffff
14 else if ((a & 0xff0000) == 0x390000) {
15 // this is rewritten 68k code
16 unsigned int a1 = a >> 1;
17 a1 = (a1 & 0x7001) | ((a1 & 0x3e) << 6) | ((a1 & 0xfc0) >> 5);
18 d = ((u16 *)svp->dram)[a1];
19 }
20
21 // "cell arrange" 2: 3a0000-3affff
22 else if ((a & 0xff0000) == 0x3a0000) {
23 // this is rewritten 68k code
24 unsigned int a1 = a >> 1;
25 a1 = (a1 & 0x7801) | ((a1 & 0x1e) << 6) | ((a1 & 0x7e0) >> 4);
26 d = ((u16 *)svp->dram)[a1];
27 }
45f2f245 28*/
29
30// IO/control area (0xa10000 - 0xa1ffff)
31static u32 PicoRead16_svpr(u32 a)
32{
33 u32 d = 0;
d26dc685 34
35 // regs
45f2f245 36 if ((a & 0xfffff0) == 0xa15000) {
d26dc685 37 switch (a & 0xf) {
38 case 0:
39 case 2:
40 d = svp->ssp1601.gr[SSP_XST].h;
41 break;
42
43 case 4:
44 d = svp->ssp1601.gr[SSP_PM0].h;
45 svp->ssp1601.gr[SSP_PM0].h &= ~1;
d26dc685 46 break;
47 }
d26dc685 48
45f2f245 49#if EL_LOGMASK & EL_SVP
50 {
51 static int a15004_looping = 0;
52 if (a == 0xa15004 && (d & 1))
53 a15004_looping = 0;
54
55 if (!a15004_looping)
56 elprintf(EL_SVP, "SVP r%i: [%06x] %04x @%06x", realsize, a, d, SekPc);
57
58 if (a == 0xa15004 && !(d&1)) {
59 if (!a15004_looping)
60 elprintf(EL_SVP, "SVP det TIGHT loop: a15004");
61 a15004_looping = 1;
62 }
63 else
64 a15004_looping = 0;
65 }
66#endif
67 return d;
d26dc685 68 }
f53f286a 69
16ebbe9e 70 //if (a == 0x30fe02 && d == 0)
71 // elprintf(EL_ANOMALY, "SVP lag?");
f8ef8ff7 72
45f2f245 73 return PicoRead16_io(a);
f53f286a 74}
75
45f2f245 76static void PicoWrite16_svpr(u32 a, u32 d)
f53f286a 77{
45f2f245 78 elprintf(EL_SVP, "SVP w16: [%06x] %04x @%06x", a, d, SekPc);
f8ef8ff7 79
45f2f245 80 if ((a & 0xfffff0) == 0xa15000) {
d26dc685 81 if (a == 0xa15000 || a == 0xa15002) {
82 // just guessing here
83 svp->ssp1601.gr[SSP_XST].h = d;
84 svp->ssp1601.gr[SSP_PM0].h |= 2;
85 svp->ssp1601.emu_status &= ~SSP_WAIT_PM0;
86 }
87 //else if (a == 0xa15006) svp->ssp1601.gr[SSP_PM0].h = d | (d << 1);
88 // 0xa15006 probably has 'halt'
45f2f245 89 return;
d26dc685 90 }
d26dc685 91
45f2f245 92 PicoWrite16_io(a, d);
93/*
30752975 94 if (a == 0x30fe06 && d != 0)
d26dc685 95 svp->ssp1601.emu_status &= ~SSP_WAIT_30FE06;
30752975 96
97 if (a == 0x30fe08 && d != 0)
d26dc685 98 svp->ssp1601.emu_status &= ~SSP_WAIT_30FE08;
45f2f245 99*/
100}
101
102void PicoSVPMemSetup(void)
103{
104 // 68k memmap:
105 // DRAM
106 cpu68k_map_set(m68k_read8_map, 0x300000, 0x31ffff, svp->dram, 0);
107 cpu68k_map_set(m68k_read16_map, 0x300000, 0x31ffff, svp->dram, 0);
108 cpu68k_map_set(m68k_write8_map, 0x300000, 0x31ffff, svp->dram, 0);
109 cpu68k_map_set(m68k_write16_map, 0x300000, 0x31ffff, svp->dram, 0);
30752975 110
45f2f245 111 // DRAM (cell arrange) - TODO
f8ef8ff7 112
45f2f245 113 // regs
114 cpu68k_map_set(m68k_read8_map, 0xa10000, 0xa1ffff, PicoRead8_io, 1); // PicoRead8_svpr
115 cpu68k_map_set(m68k_read16_map, 0xa10000, 0xa1ffff, PicoRead16_svpr, 1);
116 cpu68k_map_set(m68k_write8_map, 0xa10000, 0xa1ffff, PicoWrite8_io, 1); // PicoWrite8_svpr
117 cpu68k_map_set(m68k_write16_map, 0xa10000, 0xa1ffff, PicoWrite16_svpr, 1);
f53f286a 118}
119