f53f286a |
1 | #include "../../PicoInt.h" |
2 | |
f8ef8ff7 |
3 | #ifndef UTYPES_DEFINED |
4 | typedef unsigned char u8; |
5 | typedef unsigned short u16; |
6 | typedef unsigned int u32; |
7 | #define UTYPES_DEFINED |
8 | #endif |
9 | |
10 | #define CLEAR_DETECT(pc_start,pc_end,text) \ |
11 | if (d == 0 && SekPc >= pc_start && SekPc < pc_end) \ |
12 | { \ |
13 | if (!clearing_ram) \ |
689fb2c0 |
14 | elprintf(EL_SVP, text); \ |
f8ef8ff7 |
15 | clearing_ram = 1; \ |
16 | return; \ |
17 | } |
18 | |
f53f286a |
19 | unsigned int PicoSVPRead16(unsigned int a, int realsize) |
20 | { |
21 | unsigned int d = 0; |
d26dc685 |
22 | static int a15004_looping = 0; |
f53f286a |
23 | |
d26dc685 |
24 | // dram: 300000-31ffff |
25 | if ((a & 0xfe0000) == 0x300000) |
5de27868 |
26 | d = *(u16 *)(svp->dram + (a&0x1fffe)); |
f8ef8ff7 |
27 | |
d26dc685 |
28 | // "cell arrange" 1: 390000-39ffff |
29 | else if ((a & 0xff0000) == 0x390000) { |
30 | // this is rewritten 68k code |
31 | unsigned int a1 = a >> 1; |
32 | a1 = (a1 & 0x7001) | ((a1 & 0x3e) << 6) | ((a1 & 0xfc0) >> 5); |
33 | d = ((u16 *)svp->dram)[a1]; |
34 | } |
35 | |
36 | // "cell arrange" 2: 3a0000-3affff |
37 | else if ((a & 0xff0000) == 0x3a0000) { |
38 | // this is rewritten 68k code |
39 | unsigned int a1 = a >> 1; |
40 | a1 = (a1 & 0x7801) | ((a1 & 0x1e) << 6) | ((a1 & 0x7e0) >> 4); |
41 | d = ((u16 *)svp->dram)[a1]; |
42 | } |
43 | |
44 | // regs |
45 | else if ((a & 0xfffff0) == 0xa15000) { |
46 | switch (a & 0xf) { |
47 | case 0: |
48 | case 2: |
49 | d = svp->ssp1601.gr[SSP_XST].h; |
50 | break; |
51 | |
52 | case 4: |
53 | d = svp->ssp1601.gr[SSP_PM0].h; |
54 | svp->ssp1601.gr[SSP_PM0].h &= ~1; |
55 | if (d&1) a15004_looping = 0; |
56 | break; |
57 | } |
58 | } |
59 | else |
689fb2c0 |
60 | elprintf(EL_UIO|EL_SVP|EL_ANOMALY, "SVP FIXME: unhandled r%i: [%06x] %04x @%06x", realsize, a&0xffffff, d, SekPc); |
d26dc685 |
61 | |
62 | if (!a15004_looping) |
689fb2c0 |
63 | elprintf(EL_SVP, "SVP r%i: [%06x] %04x @%06x", realsize, a&0xffffff, d, SekPc); |
d26dc685 |
64 | |
65 | if (a == 0xa15004 && !(d&1)) { |
66 | if (!a15004_looping) |
67 | elprintf(EL_SVP, "SVP det TIGHT loop: a15004"); |
68 | a15004_looping = 1; |
69 | } |
70 | else a15004_looping = 0; |
f53f286a |
71 | |
689fb2c0 |
72 | if (a == 0x30fe02 && d == 0) |
73 | elprintf(EL_ANOMALY, "SVP lag?"); |
f8ef8ff7 |
74 | |
f53f286a |
75 | return d; |
76 | } |
77 | |
78 | void PicoSVPWrite8(unsigned int a, unsigned int d, int realsize) |
79 | { |
689fb2c0 |
80 | elprintf(EL_UIO|EL_SVP|EL_ANOMALY, "!!! SVP w%i: [%06x], %08x @%06x", realsize, a&0xffffff, d, SekPc); |
f8ef8ff7 |
81 | } |
82 | |
83 | void PicoSVPWrite16(unsigned int a, unsigned int d, int realsize) |
84 | { |
85 | static int clearing_ram = 0; |
86 | |
d26dc685 |
87 | // DRAM |
88 | if ((a & 0xfe0000) == 0x300000) |
5de27868 |
89 | *(u16 *)(svp->dram + (a&0x1fffe)) = d; |
f8ef8ff7 |
90 | |
d26dc685 |
91 | // regs |
92 | else if ((a & 0xfffff0) == 0xa15000) { |
93 | if (a == 0xa15000 || a == 0xa15002) { |
94 | // just guessing here |
95 | svp->ssp1601.gr[SSP_XST].h = d; |
96 | svp->ssp1601.gr[SSP_PM0].h |= 2; |
97 | svp->ssp1601.emu_status &= ~SSP_WAIT_PM0; |
98 | } |
99 | //else if (a == 0xa15006) svp->ssp1601.gr[SSP_PM0].h = d | (d << 1); |
100 | // 0xa15006 probably has 'halt' |
101 | } |
102 | |
103 | |
30752975 |
104 | if (a == 0x30fe06 && d != 0) |
d26dc685 |
105 | svp->ssp1601.emu_status &= ~SSP_WAIT_30FE06; |
30752975 |
106 | |
107 | if (a == 0x30fe08 && d != 0) |
d26dc685 |
108 | svp->ssp1601.emu_status &= ~SSP_WAIT_30FE08; |
30752975 |
109 | |
f8ef8ff7 |
110 | // debug: detect RAM clears.. |
30752975 |
111 | CLEAR_DETECT(0x0221dc, 0x0221f0, "SVP RAM CLEAR (full) @ 0221C2"); |
112 | CLEAR_DETECT(0x02204c, 0x022068, "SVP RAM CLEAR 300000-31ffbf (1) @ 022032"); |
f8ef8ff7 |
113 | CLEAR_DETECT(0x021900, 0x021ff0, "SVP RAM CLEAR 300000-305fff"); |
30752975 |
114 | CLEAR_DETECT(0x0220b0, 0x0220cc, "SVP RAM CLEAR 300000-31ffbf (2) @ 022096"); |
f8ef8ff7 |
115 | clearing_ram = 0; |
116 | |
689fb2c0 |
117 | elprintf(EL_SVP, "SVP w%i: [%06x] %04x @%06x", realsize, a&0xffffff, d, SekPc); |
f53f286a |
118 | } |
119 | |