1 #include "../PicoInt.h"
2 #include "../sound/sn76496.h"
5 typedef unsigned char u8;
6 typedef unsigned short u16;
7 typedef unsigned int u32;
12 // -----------------------------------------------------------------
13 // Read Rom and read Ram
15 static u32 PicoReadPico8(u32 a)
19 if ((a&0xe00000)==0xe00000) { d = *(u8 *)(Pico.ram+((a^1)&0xffff)); goto end; } // Ram
20 if (a<Pico.romsize) { d = *(u8 *)(Pico.rom+(a^1)); goto end; } // Rom
24 if ((a&0xfffff0)==0xc00000) { // VDP
29 if ((a&0xffffe0)==0x800000) // Pico I/O
33 case 0x01: d = PicoPicohw.r1; break;
35 d = PicoPad[0]&0x1f; // d-pad
36 d |= (PicoPad[0]&0x20) << 2; // pen push -> C
40 case 0x05: d = (PicoPicohw.pen_pos[0] >> 8); break; // what is MS bit for? Games read it..
41 case 0x07: d = PicoPicohw.pen_pos[0] & 0xff; break;
42 case 0x09: d = (PicoPicohw.pen_pos[1] >> 8); break;
43 case 0x0b: d = PicoPicohw.pen_pos[1] & 0xff; break;
44 case 0x0d: d = (1 << (PicoPicohw.page & 7)) - 1; break;
45 case 0x12: d = PicoPicohw.fifo_bytes == 0 ? 0x80 : 0; break; // guess
47 elprintf(EL_UIO, "r8 : %06x, %02x @%06x", a&0xffffff, (u8)d, SekPc);
52 //elprintf(EL_UIO, "r8 : %06x, %02x @%06x", a&0xffffff, (u8)d, SekPc);
55 elprintf(EL_IO, "r8 : %06x, %02x @%06x", a&0xffffff, (u8)d, SekPc);
59 static u32 PicoReadPico16(u32 a)
63 if ((a&0xe00000)==0xe00000) { d=*(u16 *)(Pico.ram+(a&0xfffe)); goto end; } // Ram
67 if (a<Pico.romsize) { d = *(u16 *)(Pico.rom+a); goto end; } // Rom
69 if ((a&0xfffff0)==0xc00000) {
75 d = (PicoPicohw.fifo_bytes > 0x3f) ? 0 : (0x3f - PicoPicohw.fifo_bytes);
76 else if (a == 0x800012)
77 d = PicoPicohw.fifo_bytes == 0 ? 0x8000 : 0; // guess
79 elprintf(EL_UIO, "r16: %06x, %04x @%06x", a&0xffffff, d, SekPc);
81 //elprintf(EL_UIO, "r16: %06x, %04x @%06x", a&0xffffff, d, SekPc);
84 elprintf(EL_IO, "r16: %06x, %04x @%06x", a&0xffffff, d, SekPc);
88 static u32 PicoReadPico32(u32 a)
92 if ((a&0xe00000)==0xe00000) { u16 *pm=(u16 *)(Pico.ram+(a&0xfffe)); d = (pm[0]<<16)|pm[1]; goto end; } // Ram
96 if (a<Pico.romsize) { u16 *pm=(u16 *)(Pico.rom+a); d = (pm[0]<<16)|pm[1]; goto end; } // Rom
98 if ((a&0xfffff0)==0xc00000) {
99 d = (PicoVideoRead(a)<<16)|PicoVideoRead(a+2);
103 elprintf(EL_UIO, "r32: %06x, %08x @%06x", a&0xffffff, d, SekPc);
106 elprintf(EL_IO, "r32: %06x, %08x @%06x", a&0xffffff, d, SekPc);
110 // -----------------------------------------------------------------
115 static FILE *f[0x10] = { NULL, };
117 int num = PicoPicohw.r12 & 0xf;
119 w = (w << 8) | (w >> 8);
120 sprintf(fname, "ldump%i.bin", num);
122 f[num] = fopen(fname, "wb");
123 fwrite(&w, 1, 2, f[num]);
128 static void PicoWritePico8(u32 a,u8 d)
130 elprintf(EL_IO, "w8 : %06x, %02x @%06x", a&0xffffff, d, SekPc);
132 if ((a&0xe00000)==0xe00000) { *(u8 *)(Pico.ram+((a^1)&0xffff))=d; return; } // Ram
135 if ((a&0xfffff9)==0xc00011) { if (PicoOpt&2) SN76496Write(d); return; } // PSG Sound
137 if ((a&0xfffff0)==0xc00000) { // VDP
139 PicoVideoWrite(a,(u16)(d|(d<<8))); // Byte access gets mirrored
144 case 0x19: case 0x1b: case 0x1d: case 0x1f: break; // 'S' 'E' 'G' 'A'
146 elprintf(EL_UIO, "w8 : %06x, %02x @%06x", a&0xffffff, d, SekPc);
149 //elprintf(EL_UIO, "w8 : %06x, %02x @%06x", a&0xffffff, d, SekPc);
152 static void PicoWritePico16(u32 a,u16 d)
154 elprintf(EL_IO, "w16: %06x, %04x", a&0xffffff, d);
156 if ((a&0xe00000)==0xe00000) { *(u16 *)(Pico.ram+(a&0xfffe))=d; return; } // Ram
159 if ((a&0xfffff0)==0xc00000) { PicoVideoWrite(a,(u16)d); return; } // VDP
161 //if (a == 0x800010) dump(d);
164 PicoPicohw.fifo_bytes += 2;
166 if (PicoPicohw.xpcm_ptr < PicoPicohw.xpcm_buffer + XPCM_BUFFER_SIZE) {
167 *PicoPicohw.xpcm_ptr++ = d >> 8;
168 *PicoPicohw.xpcm_ptr++ = d;
170 else if (PicoPicohw.xpcm_ptr == PicoPicohw.xpcm_buffer + XPCM_BUFFER_SIZE) {
171 elprintf(EL_ANOMALY|EL_PICOHW, "xpcm_buffer overflow!");
172 PicoPicohw.xpcm_ptr++;
175 else if (a == 0x800012) {
176 int r12_old = PicoPicohw.r12;
182 elprintf(EL_UIO, "w16: %06x, %04x", a&0xffffff, d);
184 //elprintf(EL_UIO, "w16: %06x, %04x", a&0xffffff, d);
187 static void PicoWritePico32(u32 a,u32 d)
189 elprintf(EL_IO, "w32: %06x, %08x", a&0xffffff, d);
191 if ((a&0xe00000)==0xe00000)
194 u16 *pm=(u16 *)(Pico.ram+(a&0xfffe));
195 pm[0]=(u16)(d>>16); pm[1]=(u16)d;
200 if ((a&0xfffff0)==0xc00000)
203 PicoVideoWrite(a, (u16)(d>>16));
204 PicoVideoWrite(a+2,(u16)d);
208 elprintf(EL_UIO, "w32: %06x, %08x", a&0xffffff, d);
212 extern unsigned int (*pm68k_read_memory_8) (unsigned int address);
213 extern unsigned int (*pm68k_read_memory_16)(unsigned int address);
214 extern unsigned int (*pm68k_read_memory_32)(unsigned int address);
215 extern void (*pm68k_write_memory_8) (unsigned int address, unsigned char value);
216 extern void (*pm68k_write_memory_16)(unsigned int address, unsigned short value);
217 extern void (*pm68k_write_memory_32)(unsigned int address, unsigned int value);
218 extern unsigned int (*pm68k_read_memory_pcr_8) (unsigned int address);
219 extern unsigned int (*pm68k_read_memory_pcr_16)(unsigned int address);
220 extern unsigned int (*pm68k_read_memory_pcr_32)(unsigned int address);
222 static unsigned int m68k_read_memory_pcrp_8(unsigned int a)
224 if((a&0xe00000)==0xe00000) return *(u8 *)(Pico.ram+((a^1)&0xffff)); // Ram
228 static unsigned int m68k_read_memory_pcrp_16(unsigned int a)
230 if((a&0xe00000)==0xe00000) return *(u16 *)(Pico.ram+(a&0xfffe)); // Ram
234 static unsigned int m68k_read_memory_pcrp_32(unsigned int a)
236 if((a&0xe00000)==0xe00000) { u16 *pm=(u16 *)(Pico.ram+(a&0xfffe)); return (pm[0]<<16)|pm[1]; } // Ram
242 PICO_INTERNAL void PicoMemSetupPico(void)
245 PicoCpuCM68k.checkpc=PicoCheckPc;
246 PicoCpuCM68k.fetch8 =PicoCpuCM68k.read8 =PicoReadPico8;
247 PicoCpuCM68k.fetch16=PicoCpuCM68k.read16=PicoReadPico16;
248 PicoCpuCM68k.fetch32=PicoCpuCM68k.read32=PicoReadPico32;
249 PicoCpuCM68k.write8 =PicoWritePico8;
250 PicoCpuCM68k.write16=PicoWritePico16;
251 PicoCpuCM68k.write32=PicoWritePico32;
254 pm68k_read_memory_8 = PicoReadPico8;
255 pm68k_read_memory_16 = PicoReadPico16;
256 pm68k_read_memory_32 = PicoReadPico32;
257 pm68k_write_memory_8 = PicoWritePico8;
258 pm68k_write_memory_16 = PicoWritePico16;
259 pm68k_write_memory_32 = PicoWritePico32;
260 pm68k_read_memory_pcr_8 = m68k_read_memory_pcrp_8;
261 pm68k_read_memory_pcr_16 = m68k_read_memory_pcrp_16;
262 pm68k_read_memory_pcr_32 = m68k_read_memory_pcrp_32;
265 // use standard setup, only override handlers
267 PicoCpuFM68k.read_byte =PicoReadPico8;
268 PicoCpuFM68k.read_word =PicoReadPico16;
269 PicoCpuFM68k.read_long =PicoReadPico32;
270 PicoCpuFM68k.write_byte=PicoWritePico8;
271 PicoCpuFM68k.write_word=PicoWritePico16;
272 PicoCpuFM68k.write_long=PicoWritePico32;