code region dump added for Musashi
[picodrive.git] / Pico / Pico / Memory.c
CommitLineData
9037e45d 1#include "../PicoInt.h"
2
3#ifndef UTYPES_DEFINED
4typedef unsigned char u8;
5typedef unsigned short u16;
6typedef unsigned int u32;
7#define UTYPES_DEFINED
8#endif
9
10// -----------------------------------------------------------------
11// Read Rom and read Ram
12
13static u32 PicoReadPico8(u32 a)
14{
15 u32 d=0;
16
17 if ((a&0xe00000)==0xe00000) { d = *(u8 *)(Pico.ram+((a^1)&0xffff)); goto end; } // Ram
18 if (a<Pico.romsize) { d = *(u8 *)(Pico.rom+(a^1)); goto end; } // Rom
19
20 a&=0xffffff;
21
22 if ((a&0xffffe0)==0xc00000) { // VDP
23 d=PicoVideoRead(a);
24 if ((a&1)==0) d>>=8;
25 goto end;
26 }
27
28 elprintf(EL_UIO, "r8 : %06x, %02x @%06x", a&0xffffff, (u8)d, SekPc);
29
30end:
31 elprintf(EL_IO, "r8 : %06x, %02x @%06x", a&0xffffff, (u8)d, SekPc);
32 return d;
33}
34
35static u32 PicoReadPico16(u32 a)
36{
37 u32 d=0;
38
39 if ((a&0xe00000)==0xe00000) { d=*(u16 *)(Pico.ram+(a&0xfffe)); goto end; } // Ram
40
41 a&=0xfffffe;
42
43 if (a<Pico.romsize) { d = *(u16 *)(Pico.rom+a); goto end; } // Rom
44
45 if ((a&0xffffe0)==0xc00000) {
46 d = PicoVideoRead(a);
47 goto end;
48 }
49
50 elprintf(EL_UIO, "r16: %06x, %04x @%06x", a&0xffffff, d, SekPc);
51
52end:
53 elprintf(EL_IO, "r16: %06x, %04x @%06x", a&0xffffff, d, SekPc);
54 return d;
55}
56
57static u32 PicoReadPico32(u32 a)
58{
59 u32 d=0;
60
61 if ((a&0xe00000)==0xe00000) { u16 *pm=(u16 *)(Pico.ram+(a&0xfffe)); d = (pm[0]<<16)|pm[1]; goto end; } // Ram
62
63 a&=0xfffffe;
64
65 if (a<Pico.romsize) { u16 *pm=(u16 *)(Pico.rom+a); d = (pm[0]<<16)|pm[1]; goto end; } // Rom
66
67 if ((a&0xffffe0)==0xc00000) {
68 d = (PicoVideoRead(a)<<16)|PicoVideoRead(a+2);
69 goto end;
70 }
71
72 elprintf(EL_UIO, "r32: %06x, %08x @%06x", a&0xffffff, d, SekPc);
73
74end:
75 elprintf(EL_IO, "r32: %06x, %08x @%06x", a&0xffffff, d, SekPc);
76 return d;
77}
78
79// -----------------------------------------------------------------
80// Write Ram
81
82static void PicoWritePico8(u32 a,u8 d)
83{
84 elprintf(EL_IO, "w8 : %06x, %02x @%06x", a&0xffffff, d, SekPc);
85
86 if ((a&0xe00000)==0xe00000) { *(u8 *)(Pico.ram+((a^1)&0xffff))=d; return; } // Ram
87
88 a&=0xffffff;
89 if ((a&0xffffe0)==0xc00000) { // VDP
90 d&=0xff;
91 PicoVideoWrite(a,(u16)(d|(d<<8))); // Byte access gets mirrored
92 return;
93 }
94
95 elprintf(EL_UIO, "w8 : %06x, %02x @%06x", a&0xffffff, d, SekPc);
96}
97
98static void PicoWritePico16(u32 a,u16 d)
99{
100 elprintf(EL_IO, "w16: %06x, %04x", a&0xffffff, d);
101
102 if ((a&0xe00000)==0xe00000) { *(u16 *)(Pico.ram+(a&0xfffe))=d; return; } // Ram
103
104 a&=0xfffffe;
105 if ((a&0xffffe0)==0xc00000) { PicoVideoWrite(a,(u16)d); return; } // VDP
106
107 elprintf(EL_UIO, "w16: %06x, %04x", a&0xffffff, d);
108}
109
110static void PicoWritePico32(u32 a,u32 d)
111{
112 elprintf(EL_IO, "w32: %06x, %08x", a&0xffffff, d);
113
114 if ((a&0xe00000)==0xe00000)
115 {
116 // Ram:
117 u16 *pm=(u16 *)(Pico.ram+(a&0xfffe));
118 pm[0]=(u16)(d>>16); pm[1]=(u16)d;
119 return;
120 }
121
122 a&=0xfffffe;
123 if ((a&0xffffe0)==0xc00000)
124 {
125 // VDP:
126 PicoVideoWrite(a, (u16)(d>>16));
127 PicoVideoWrite(a+2,(u16)d);
128 return;
129 }
130
131 elprintf(EL_UIO, "w32: %06x, %08x", a&0xffffff, d);
132}
133
134#ifdef EMU_M68K
135extern unsigned int (*pm68k_read_memory_8) (unsigned int address);
136extern unsigned int (*pm68k_read_memory_16)(unsigned int address);
137extern unsigned int (*pm68k_read_memory_32)(unsigned int address);
138extern void (*pm68k_write_memory_8) (unsigned int address, unsigned char value);
139extern void (*pm68k_write_memory_16)(unsigned int address, unsigned short value);
140extern void (*pm68k_write_memory_32)(unsigned int address, unsigned int value);
141extern unsigned int (*pm68k_read_memory_pcr_8) (unsigned int address);
142extern unsigned int (*pm68k_read_memory_pcr_16)(unsigned int address);
143extern unsigned int (*pm68k_read_memory_pcr_32)(unsigned int address);
144
145static unsigned int m68k_read_memory_pcrp_8(unsigned int a)
146{
147 if((a&0xe00000)==0xe00000) return *(u8 *)(Pico.ram+((a^1)&0xffff)); // Ram
148 return 0;
149}
150
151static unsigned int m68k_read_memory_pcrp_16(unsigned int a)
152{
153 if((a&0xe00000)==0xe00000) return *(u16 *)(Pico.ram+(a&0xfffe)); // Ram
154 return 0;
155}
156
157static unsigned int m68k_read_memory_pcrp_32(unsigned int a)
158{
159 if((a&0xe00000)==0xe00000) { u16 *pm=(u16 *)(Pico.ram+(a&0xfffe)); return (pm[0]<<16)|pm[1]; } // Ram
160 return 0;
161}
162#endif // EMU_M68K
163
164
165PICO_INTERNAL void PicoMemSetupPico(void)
166{
167#ifdef EMU_M68K
168 pm68k_read_memory_8 = PicoReadPico8;
169 pm68k_read_memory_16 = PicoReadPico16;
170 pm68k_read_memory_32 = PicoReadPico32;
171 pm68k_write_memory_8 = PicoWritePico8;
172 pm68k_write_memory_16 = PicoWritePico16;
173 pm68k_write_memory_32 = PicoWritePico32;
174 pm68k_read_memory_pcr_8 = m68k_read_memory_pcrp_8;
175 pm68k_read_memory_pcr_16 = m68k_read_memory_pcrp_16;
176 pm68k_read_memory_pcr_32 = m68k_read_memory_pcrp_32;
177#endif
178}
179