1 // This is part of Pico Library
\r
3 // (c) Copyright 2004 Dave, All rights reserved.
\r
4 // (c) Copyright 2006,2007 notaz, All rights reserved.
\r
5 // Free for non-commercial use.
\r
7 // For commercial use, separate licencing terms must be obtained.
\r
10 #include "PicoInt.h"
\r
12 #include "sound/ym2612.h"
\r
13 #include "sound/sn76496.h"
\r
15 #ifndef UTYPES_DEFINED
\r
16 typedef unsigned char u8;
\r
17 typedef unsigned short u16;
\r
18 typedef unsigned int u32;
\r
19 #define UTYPES_DEFINED
\r
22 extern unsigned int lastSSRamWrite; // used by serial SRAM code
\r
24 #ifdef _ASM_MEMORY_C
\r
25 u32 PicoRead8(u32 a);
\r
26 u32 PicoRead16(u32 a);
\r
27 void PicoWrite8(u32 a,u8 d);
\r
28 void PicoWriteRomHW_SSF2(u32 a,u32 d);
\r
32 #ifdef EMU_CORE_DEBUG
\r
33 u32 lastread_a, lastread_d[16]={0,}, lastwrite_cyc_d[16]={0,}, lastwrite_mus_d[16]={0,};
\r
34 int lrp_cyc=0, lrp_mus=0, lwp_cyc=0, lwp_mus=0;
\r
35 extern unsigned int ppop;
\r
39 void log_io(unsigned int addr, int bits, int rw);
\r
40 #elif defined(_MSC_VER)
\r
46 #if defined(EMU_C68K)
\r
47 static __inline int PicoMemBase(u32 pc)
\r
51 if (pc<Pico.romsize+4)
\r
53 membase=(int)Pico.rom; // Program Counter in Rom
\r
55 else if ((pc&0xe00000)==0xe00000)
\r
57 membase=(int)Pico.ram-(pc&0xff0000); // Program Counter in Ram
\r
61 // Error - Program Counter is invalid
\r
62 membase=(int)Pico.rom;
\r
70 static u32 PicoCheckPc(u32 pc)
\r
73 #if defined(EMU_C68K)
\r
74 pc-=PicoCpuCM68k.membase; // Get real pc
\r
79 printf("%i:%03i: game crash detected @ %06x\n", Pico.m.frame_count, Pico.m.scanline, SekPc);
\r
80 return (int)Pico.rom + Pico.romsize; // common crash condition, can happen if acc timing is off
\r
83 PicoCpuCM68k.membase=PicoMemBase(pc&0x00ffffff);
\r
84 PicoCpuCM68k.membase-=pc&0xff000000;
\r
86 ret = PicoCpuCM68k.membase+pc;
\r
92 PICO_INTERNAL int PicoInitPc(u32 pc)
\r
98 #ifndef _ASM_MEMORY_C
\r
99 PICO_INTERNAL_ASM void PicoMemReset(void)
\r
104 // -----------------------------------------------------------------
\r
108 int pad,value,data_reg;
\r
109 pad=~PicoPad[i]; // Get inverse of pad MXYZ SACB RLDU
\r
110 data_reg=Pico.ioports[i+1];
\r
112 // orr the bits, which are set as output
\r
113 value = data_reg&(Pico.ioports[i+4]|0x80);
\r
115 if(PicoOpt & 0x20) { // 6 button gamepad enabled
\r
116 int phase = Pico.m.padTHPhase[i];
\r
118 if(phase == 2 && !(data_reg&0x40)) { // TH
\r
119 value|=(pad&0xc0)>>2; // ?0SA 0000
\r
121 } else if(phase == 3) {
\r
123 value|=(pad&0x30)|((pad>>8)&0xf); // ?1CB MXYZ
\r
125 value|=((pad&0xc0)>>2)|0x0f; // ?0SA 1111
\r
130 if(data_reg&0x40) // TH
\r
131 value|=(pad&0x3f); // ?1CB RLDU
\r
132 else value|=((pad&0xc0)>>2)|(pad&3); // ?0SA 00DU
\r
134 return value; // will mirror later
\r
138 #ifndef _ASM_MEMORY_C
\r
141 u32 SRAMRead(u32 a)
\r
143 unsigned int sreg = Pico.m.sram_reg;
\r
144 if (!(sreg & 0x10) && (sreg & 1) && a > 0x200001) { // not yet detected SRAM
\r
145 elprintf(EL_SRAMIO, "normal sram detected.");
\r
146 Pico.m.sram_reg|=0x10; // should be normal SRAM
\r
148 if (sreg & 4) // EEPROM read
\r
149 return SRAMReadEEPROM();
\r
150 else // if(sreg & 1) // (sreg&5) is one of prerequisites
\r
151 return *(u8 *)(SRam.data-SRam.start+a);
\r
154 #ifndef _ASM_MEMORY_C
\r
157 u32 SRAMRead16(u32 a)
\r
160 if (Pico.m.sram_reg & 4) {
\r
161 d = SRAMReadEEPROM();
\r
164 u8 *pm=(u8 *)(SRam.data-SRam.start+a);
\r
171 static void SRAMWrite(u32 a, u32 d)
\r
173 unsigned int sreg = Pico.m.sram_reg;
\r
174 if(!(sreg & 0x10)) {
\r
175 // not detected SRAM
\r
176 if((a&~1)==0x200000) {
\r
177 elprintf(EL_SRAMIO, "eeprom detected.");
\r
178 sreg|=4; // this should be a game with EEPROM (like NBA Jam)
\r
179 SRam.start=0x200000; SRam.end=SRam.start+1;
\r
181 elprintf(EL_SRAMIO, "normal sram detected.");
\r
183 Pico.m.sram_reg=sreg;
\r
185 if(sreg & 4) { // EEPROM write
\r
186 // this diff must be at most 16 for NBA Jam to work
\r
187 if(SekCyclesDoneT()-lastSSRamWrite < 16) {
\r
188 // just update pending state
\r
189 elprintf(EL_EEPROM, "eeprom: skip because cycles=%i", SekCyclesDoneT()-lastSSRamWrite);
\r
190 SRAMUpdPending(a, d);
\r
193 SRAMWriteEEPROM(sreg>>6); // execute pending
\r
194 SRAMUpdPending(a, d);
\r
195 if ((old^Pico.m.sram_reg)&0xc0) // update time only if SDA/SCL changed
\r
196 lastSSRamWrite = SekCyclesDoneT();
\r
198 } else if(!(sreg & 2)) {
\r
199 u8 *pm=(u8 *)(SRam.data-SRam.start+a);
\r
207 // for nonstandard reads
\r
208 static u32 OtherRead16End(u32 a, int realsize)
\r
212 // for games with simple protection devices, discovered by Haze
\r
213 // some dumb detection is used, but that should be enough to make things work
\r
214 if ((a>>22) == 1 && Pico.romsize >= 512*1024) {
\r
215 if (*(int *)(Pico.rom+0x123e4) == 0x00550c39 && *(int *)(Pico.rom+0x123e8) == 0x00000040) { // Super Bubble Bobble (Unl) [!]
\r
216 if (a == 0x400000) { d=0x55<<8; goto end; }
\r
217 else if (a == 0x400002) { d=0x0f<<8; goto end; }
\r
219 else if (*(int *)(Pico.rom+0x008c4) == 0x66240055 && *(int *)(Pico.rom+0x008c8) == 0x00404df9) { // Smart Mouse (Unl)
\r
220 if (a == 0x400000) { d=0x55<<8; goto end; }
\r
221 else if (a == 0x400002) { d=0x0f<<8; goto end; }
\r
222 else if (a == 0x400004) { d=0xaa<<8; goto end; }
\r
223 else if (a == 0x400006) { d=0xf0<<8; goto end; }
\r
225 else if (*(int *)(Pico.rom+0x00404) == 0x00a90600 && *(int *)(Pico.rom+0x00408) == 0x6708b013) { // King of Fighters '98, The (Unl) [!]
\r
226 if (a == 0x480000 || a == 0x4800e0 || a == 0x4824a0 || a == 0x488880) { d=0xaa<<8; goto end; }
\r
227 else if (a == 0x4a8820) { d=0x0a<<8; goto end; }
\r
228 // there is also a read @ 0x4F8820 which needs 0, but that is returned in default case
\r
230 else if (*(int *)(Pico.rom+0x01b24) == 0x004013f9 && *(int *)(Pico.rom+0x01b28) == 0x00ff0000) { // Mahjong Lover (Unl) [!]
\r
231 if (a == 0x400000) { d=0x90<<8; goto end; }
\r
232 else if (a == 0x401000) { d=0xd3<<8; goto end; } // this one doesn't seem to be needed, the code does 2 comparisons and only then
\r
233 // checks the result, which is of the above one. Left it just in case.
\r
235 else if (*(int *)(Pico.rom+0x05254) == 0x0c3962d0 && *(int *)(Pico.rom+0x05258) == 0x00400055) { // Elf Wor (Unl)
\r
236 if (a == 0x400000) { d=0x55<<8; goto end; }
\r
237 else if (a == 0x400004) { d=0xc9<<8; goto end; } // this check is done if the above one fails
\r
238 else if (a == 0x400002) { d=0x0f<<8; goto end; }
\r
239 else if (a == 0x400006) { d=0x18<<8; goto end; } // similar to above
\r
241 // our default behaviour is to return whatever was last written a 0x400000-0x7fffff range (used by Squirrel King (R) [!])
\r
242 // Lion King II, The (Unl) [!] writes @ 400000 and wants to get that val @ 400002 and wites another val
\r
243 // @ 400004 which is expected @ 400006, so we really remember 2 values here
\r
244 d = Pico.m.prot_bytes[(a>>2)&1]<<8;
\r
246 else if (a == 0xa13000 && Pico.romsize >= 1024*1024) {
\r
247 if (*(int *)(Pico.rom+0xc8af0) == 0x30133013 && *(int *)(Pico.rom+0xc8af4) == 0x000f0240) { // Rockman X3 (Unl) [!]
\r
250 else if (*(int *)(Pico.rom+0x28888) == 0x07fc0000 && *(int *)(Pico.rom+0x2888c) == 0x4eb94e75) { // Bug's Life, A (Unl) [!]
\r
251 d=0x28; goto end; // does the check from RAM
\r
253 else if (*(int *)(Pico.rom+0xc8778) == 0x30133013 && *(int *)(Pico.rom+0xc877c) == 0x000f0240) { // Super Mario Bros. (Unl) [!]
\r
254 d=0x0c; goto end; // seems to be the same code as in Rockman X3 (Unl) [!]
\r
256 else if (*(int *)(Pico.rom+0xf20ec) == 0x30143013 && *(int *)(Pico.rom+0xf20f0) == 0x000f0200) { // Super Mario 2 1998 (Unl) [!]
\r
260 else if (a == 0xa13002) { // Pocket Monsters (Unl)
\r
263 else if (a == 0xa1303E) { // Pocket Monsters (Unl)
\r
266 else if (a == 0x30fe02) {
\r
267 // Virtua Racing - just for fun
\r
268 // this seems to be some flag that SVP is ready or something similar
\r
273 elprintf(EL_UIO, "strange r%i: [%06x] %04x @%06x", realsize, a&0xffffff, d, SekPc);
\r
278 //extern UINT32 mz80GetRegisterValue(void *, UINT32);
\r
280 static void OtherWrite8End(u32 a,u32 d,int realsize)
\r
283 if(a >= SRam.start && a <= SRam.end) {
\r
284 elprintf(EL_SRAMIO, "sram w8 [%06x] %02x @ %06x", a, d, SekPc);
\r
289 #ifdef _ASM_MEMORY_C
\r
290 // special ROM hardware (currently only banking and sram reg supported)
\r
291 if((a&0xfffff1) == 0xA130F1) {
\r
292 PicoWriteRomHW_SSF2(a, d); // SSF2 or SRAM
\r
296 // sram access register
\r
297 if(a == 0xA130F1) {
\r
298 elprintf(EL_SRAMIO, "sram reg=%02x", d);
\r
299 Pico.m.sram_reg &= ~3;
\r
300 Pico.m.sram_reg |= (u8)(d&3);
\r
304 elprintf(EL_UIO, "strange w%i: %06x, %08x @%06x", realsize, a&0xffffff, d, SekPc);
\r
306 if(a >= 0xA13004 && a < 0xA13040) {
\r
307 // dumb 12-in-1 or 4-in-1 banking support
\r
309 a &= 0x3f; a <<= 16;
\r
310 len = Pico.romsize - a;
\r
311 if (len <= 0) return; // invalid/missing bank
\r
312 if (len > 0x200000) len = 0x200000; // 2 megs
\r
313 memcpy(Pico.rom, Pico.rom+a, len); // code which does this is in RAM so this is safe.
\r
317 // for games with simple protection devices, discovered by Haze
\r
318 else if ((a>>22) == 1)
\r
319 Pico.m.prot_bytes[(a>>2)&1] = (u8)d;
\r
322 #include "MemoryCmn.c"
\r
325 // -----------------------------------------------------------------
\r
326 // Read Rom and read Ram
\r
328 #ifndef _ASM_MEMORY_C
\r
329 PICO_INTERNAL_ASM u32 PicoRead8(u32 a)
\r
333 if ((a&0xe00000)==0xe00000) { d = *(u8 *)(Pico.ram+((a^1)&0xffff)); goto end; } // Ram
\r
337 #ifndef EMU_CORE_DEBUG
\r
339 if (a >= SRam.start && a <= SRam.end && (Pico.m.sram_reg&5)) {
\r
341 elprintf(EL_SRAMIO, "sram r8 [%06x] %02x @ %06x", a, d, SekPc);
\r
346 if (a<Pico.romsize) { d = *(u8 *)(Pico.rom+(a^1)); goto end; } // Rom
\r
348 if ((a&0xff4000)==0xa00000) { d=z80Read8(a); goto end; } // Z80 Ram
\r
350 if ((a&0xe700e0)==0xc00000) // VDP
\r
351 d=PicoVideoRead(a);
\r
352 else d=OtherRead16(a&~1, 8);
\r
353 if ((a&1)==0) d>>=8;
\r
356 elprintf(EL_IO, "r8 : %06x, %02x @%06x", a&0xffffff, (u8)d, SekPc);
\r
357 #ifdef EMU_CORE_DEBUG
\r
358 if (a>=Pico.romsize) {
\r
360 lastread_d[lrp_cyc++&15] = (u8)d;
\r
366 PICO_INTERNAL_ASM u32 PicoRead16(u32 a)
\r
370 if ((a&0xe00000)==0xe00000) { d=*(u16 *)(Pico.ram+(a&0xfffe)); goto end; } // Ram
\r
374 #ifndef EMU_CORE_DEBUG
\r
376 if (a >= SRam.start && a <= SRam.end && (Pico.m.sram_reg&5)) {
\r
378 elprintf(EL_SRAMIO, "sram r16 [%06x] %04x @ %06x", a, d, SekPc);
\r
383 if (a<Pico.romsize) { d = *(u16 *)(Pico.rom+a); goto end; } // Rom
\r
386 if ((a&0xe700e0)==0xc00000)
\r
387 d = PicoVideoRead(a);
\r
388 else d = OtherRead16(a, 16);
\r
391 elprintf(EL_IO, "r16: %06x, %04x @%06x", a&0xffffff, d, SekPc);
\r
392 #ifdef EMU_CORE_DEBUG
\r
393 if (a>=Pico.romsize) {
\r
395 lastread_d[lrp_cyc++&15] = d;
\r
401 PICO_INTERNAL_ASM u32 PicoRead32(u32 a)
\r
405 if ((a&0xe00000)==0xe00000) { u16 *pm=(u16 *)(Pico.ram+(a&0xfffe)); d = (pm[0]<<16)|pm[1]; goto end; } // Ram
\r
410 if(a >= SRam.start && a <= SRam.end && (Pico.m.sram_reg&5)) {
\r
411 d = (SRAMRead16(a)<<16)|SRAMRead16(a+2);
\r
412 elprintf(EL_SRAMIO, "sram r32 [%06x] %08x @ %06x", a, d, SekPc);
\r
416 if (a<Pico.romsize) { u16 *pm=(u16 *)(Pico.rom+a); d = (pm[0]<<16)|pm[1]; goto end; } // Rom
\r
419 if ((a&0xe700e0)==0xc00000)
\r
420 d = (PicoVideoRead(a)<<16)|PicoVideoRead(a+2);
\r
421 else d = (OtherRead16(a, 32)<<16)|OtherRead16(a+2, 32);
\r
424 elprintf(EL_IO, "r32: %06x, %08x @%06x", a&0xffffff, d, SekPc);
\r
425 #ifdef EMU_CORE_DEBUG
\r
426 if (a>=Pico.romsize) {
\r
428 lastread_d[lrp_cyc++&15] = d;
\r
435 // -----------------------------------------------------------------
\r
438 #if !defined(_ASM_MEMORY_C) || defined(_ASM_MEMORY_C_AMIPS)
\r
439 PICO_INTERNAL_ASM void PicoWrite8(u32 a,u8 d)
\r
441 elprintf(EL_IO, "w8 : %06x, %02x @%06x", a&0xffffff, d, SekPc);
\r
442 #ifdef EMU_CORE_DEBUG
\r
443 lastwrite_cyc_d[lwp_cyc++&15] = d;
\r
446 if ((a&0xe00000)==0xe00000) { *(u8 *)(Pico.ram+((a^1)&0xffff))=d; return; } // Ram
\r
454 void PicoWrite16(u32 a,u16 d)
\r
456 elprintf(EL_IO, "w16: %06x, %04x", a&0xffffff, d);
\r
457 #ifdef EMU_CORE_DEBUG
\r
458 lastwrite_cyc_d[lwp_cyc++&15] = d;
\r
461 if ((a&0xe00000)==0xe00000) { *(u16 *)(Pico.ram+(a&0xfffe))=d; return; } // Ram
\r
465 if ((a&0xe700e0)==0xc00000) { PicoVideoWrite(a,(u16)d); return; } // VDP
\r
469 static void PicoWrite32(u32 a,u32 d)
\r
471 elprintf(EL_IO, "w32: %06x, %08x", a&0xffffff, d);
\r
472 #ifdef EMU_CORE_DEBUG
\r
473 lastwrite_cyc_d[lwp_cyc++&15] = d;
\r
476 if ((a&0xe00000)==0xe00000)
\r
479 u16 *pm=(u16 *)(Pico.ram+(a&0xfffe));
\r
480 pm[0]=(u16)(d>>16); pm[1]=(u16)d;
\r
486 if ((a&0xe700e0)==0xc00000)
\r
489 PicoVideoWrite(a, (u16)(d>>16));
\r
490 PicoVideoWrite(a+2,(u16)d);
\r
494 OtherWrite16(a, (u16)(d>>16));
\r
495 OtherWrite16(a+2,(u16)d);
\r
499 // -----------------------------------------------------------------
\r
502 static void OtherWrite16End(u32 a,u32 d,int realsize)
\r
504 PicoWrite8Hook(a, d>>8, realsize);
\r
505 PicoWrite8Hook(a+1,d&0xff, realsize);
\r
508 u32 (*PicoRead16Hook) (u32 a, int realsize) = OtherRead16End;
\r
509 void (*PicoWrite8Hook) (u32 a, u32 d, int realsize) = OtherWrite8End;
\r
510 void (*PicoWrite16Hook)(u32 a, u32 d, int realsize) = OtherWrite16End;
\r
512 PICO_INTERNAL void PicoMemResetHooks(void)
\r
514 // default unmapped/cart specific handlers
\r
515 PicoRead16Hook = OtherRead16End;
\r
516 PicoWrite8Hook = OtherWrite8End;
\r
517 PicoWrite16Hook = OtherWrite16End;
\r
520 PICO_INTERNAL void PicoMemSetup(void)
\r
522 // Setup memory callbacks:
\r
524 PicoCpuCM68k.checkpc=PicoCheckPc;
\r
525 PicoCpuCM68k.fetch8 =PicoCpuCM68k.read8 =PicoRead8;
\r
526 PicoCpuCM68k.fetch16=PicoCpuCM68k.read16=PicoRead16;
\r
527 PicoCpuCM68k.fetch32=PicoCpuCM68k.read32=PicoRead32;
\r
528 PicoCpuCM68k.write8 =PicoWrite8;
\r
529 PicoCpuCM68k.write16=PicoWrite16;
\r
530 PicoCpuCM68k.write32=PicoWrite32;
\r
533 PicoCpuFM68k.read_byte =PicoRead8;
\r
534 PicoCpuFM68k.read_word =PicoRead16;
\r
535 PicoCpuFM68k.read_long =PicoRead32;
\r
536 PicoCpuFM68k.write_byte=PicoWrite8;
\r
537 PicoCpuFM68k.write_word=PicoWrite16;
\r
538 PicoCpuFM68k.write_long=PicoWrite32;
\r
540 // setup FAME fetchmap
\r
543 // by default, point everything to fitst 64k of ROM
\r
544 for (i = 0; i < M68K_FETCHBANK1; i++)
\r
545 PicoCpuFM68k.Fetch[i] = (unsigned int)Pico.rom - (i<<(24-FAMEC_FETCHBITS));
\r
547 for (i = 0; i < M68K_FETCHBANK1 && (i<<(24-FAMEC_FETCHBITS)) < Pico.romsize; i++)
\r
548 PicoCpuFM68k.Fetch[i] = (unsigned int)Pico.rom;
\r
550 for (i = M68K_FETCHBANK1*14/16; i < M68K_FETCHBANK1; i++)
\r
551 PicoCpuFM68k.Fetch[i] = (unsigned int)Pico.ram - (i<<(24-FAMEC_FETCHBITS));
\r
558 unsigned int m68k_read_pcrelative_CD8 (unsigned int a);
\r
559 unsigned int m68k_read_pcrelative_CD16(unsigned int a);
\r
560 unsigned int m68k_read_pcrelative_CD32(unsigned int a);
\r
562 // these are allowed to access RAM
\r
563 static unsigned int m68k_read_8 (unsigned int a, int do_fake)
\r
566 if(a<Pico.romsize && m68ki_cpu_p==&PicoCpuMM68k) return *(u8 *)(Pico.rom+(a^1)); // Rom
\r
567 #ifdef EMU_CORE_DEBUG
\r
568 if(do_fake&&((ppop&0x3f)==0x3a||(ppop&0x3f)==0x3b)) return lastread_d[lrp_mus++&15];
\r
570 if(PicoMCD&1) return m68k_read_pcrelative_CD8(a);
\r
571 if((a&0xe00000)==0xe00000) return *(u8 *)(Pico.ram+((a^1)&0xffff)); // Ram
\r
574 static unsigned int m68k_read_16(unsigned int a, int do_fake)
\r
577 if(a<Pico.romsize && m68ki_cpu_p==&PicoCpuMM68k) return *(u16 *)(Pico.rom+(a&~1)); // Rom
\r
578 #ifdef EMU_CORE_DEBUG
\r
579 if(do_fake&&((ppop&0x3f)==0x3a||(ppop&0x3f)==0x3b)) return lastread_d[lrp_mus++&15];
\r
581 if(PicoMCD&1) return m68k_read_pcrelative_CD16(a);
\r
582 if((a&0xe00000)==0xe00000) return *(u16 *)(Pico.ram+(a&0xfffe)); // Ram
\r
585 static unsigned int m68k_read_32(unsigned int a, int do_fake)
\r
588 if(a<Pico.romsize && m68ki_cpu_p==&PicoCpuMM68k) { u16 *pm=(u16 *)(Pico.rom+(a&~1)); return (pm[0]<<16)|pm[1]; }
\r
589 #ifdef EMU_CORE_DEBUG
\r
590 if(do_fake&&((ppop&0x3f)==0x3a||(ppop&0x3f)==0x3b)) return lastread_d[lrp_mus++&15];
\r
592 if(PicoMCD&1) return m68k_read_pcrelative_CD32(a);
\r
593 if((a&0xe00000)==0xe00000) { u16 *pm=(u16 *)(Pico.ram+(a&0xfffe)); return (pm[0]<<16)|pm[1]; } // Ram
\r
597 unsigned int m68k_read_pcrelative_8 (unsigned int a) { return m68k_read_8 (a, 1); }
\r
598 unsigned int m68k_read_pcrelative_16(unsigned int a) { return m68k_read_16(a, 1); }
\r
599 unsigned int m68k_read_pcrelative_32(unsigned int a) { return m68k_read_32(a, 1); }
\r
600 unsigned int m68k_read_immediate_16(unsigned int a) { return m68k_read_16(a, 0); }
\r
601 unsigned int m68k_read_immediate_32(unsigned int a) { return m68k_read_32(a, 0); }
\r
602 unsigned int m68k_read_disassembler_8 (unsigned int a) { return m68k_read_8 (a, 0); }
\r
603 unsigned int m68k_read_disassembler_16(unsigned int a) { return m68k_read_16(a, 0); }
\r
604 unsigned int m68k_read_disassembler_32(unsigned int a) { return m68k_read_32(a, 0); }
\r
606 #ifdef EMU_CORE_DEBUG
\r
608 unsigned int m68k_read_memory_8(unsigned int a)
\r
611 if (a<Pico.romsize && m68ki_cpu_p==&PicoCpuMM68k)
\r
612 d = *(u8 *) (Pico.rom+(a^1));
\r
613 else d = (u8) lastread_d[lrp_mus++&15];
\r
614 elprintf(EL_IO, "r8_mu : %06x, %02x @%06x", a&0xffffff, d, SekPc);
\r
617 unsigned int m68k_read_memory_16(unsigned int a)
\r
620 if (a<Pico.romsize && m68ki_cpu_p==&PicoCpuMM68k)
\r
621 d = *(u16 *)(Pico.rom+(a&~1));
\r
622 else d = (u16) lastread_d[lrp_mus++&15];
\r
623 elprintf(EL_IO, "r16_mu: %06x, %04x @%06x", a&0xffffff, d, SekPc);
\r
626 unsigned int m68k_read_memory_32(unsigned int a)
\r
629 if (a<Pico.romsize && m68ki_cpu_p==&PicoCpuMM68k)
\r
630 { u16 *pm=(u16 *)(Pico.rom+(a&~1));d=(pm[0]<<16)|pm[1]; }
\r
631 else if (a <= 0x78) d = m68k_read_32(a, 0);
\r
632 else d = lastread_d[lrp_mus++&15];
\r
633 elprintf(EL_IO, "r32_mu: %06x, %08x @%06x", a&0xffffff, d, SekPc);
\r
637 // ignore writes, Cyclone already done that
\r
638 void m68k_write_memory_8(unsigned int address, unsigned int value) { lastwrite_mus_d[lwp_mus++&15] = value; }
\r
639 void m68k_write_memory_16(unsigned int address, unsigned int value) { lastwrite_mus_d[lwp_mus++&15] = value; }
\r
640 void m68k_write_memory_32(unsigned int address, unsigned int value) { lastwrite_mus_d[lwp_mus++&15] = value; }
\r
642 unsigned char PicoReadCD8w (unsigned int a);
\r
643 unsigned short PicoReadCD16w(unsigned int a);
\r
644 unsigned int PicoReadCD32w(unsigned int a);
\r
645 void PicoWriteCD8w (unsigned int a, unsigned char d);
\r
646 void PicoWriteCD16w(unsigned int a, unsigned short d);
\r
647 void PicoWriteCD32w(unsigned int a, unsigned int d);
\r
649 /* it appears that Musashi doesn't always mask the unused bits */
\r
650 unsigned int m68k_read_memory_8(unsigned int address)
\r
652 unsigned int d = (PicoMCD&1) ? PicoReadCD8w(address) : PicoRead8(address);
\r
656 unsigned int m68k_read_memory_16(unsigned int address)
\r
658 unsigned int d = (PicoMCD&1) ? PicoReadCD16w(address) : PicoRead16(address);
\r
662 unsigned int m68k_read_memory_32(unsigned int address)
\r
664 return (PicoMCD&1) ? PicoReadCD32w(address) : PicoRead32(address);
\r
667 void m68k_write_memory_8(unsigned int address, unsigned int value)
\r
669 if (PicoMCD&1) PicoWriteCD8w(address, (u8)value); else PicoWrite8(address, (u8)value);
\r
672 void m68k_write_memory_16(unsigned int address, unsigned int value)
\r
674 if (PicoMCD&1) PicoWriteCD16w(address,(u16)value); else PicoWrite16(address,(u16)value);
\r
677 void m68k_write_memory_32(unsigned int address, unsigned int value)
\r
679 if (PicoMCD&1) PicoWriteCD32w(address, value); else PicoWrite32(address, value);
\r
685 // -----------------------------------------------------------------
\r
688 PICO_INTERNAL unsigned char z80_read(unsigned short a)
\r
692 if ((a>>13)==2) // 0x4000-0x5fff (Charles MacDonald)
\r
694 if (PicoOpt&1) ret = (u8) YM2612Read();
\r
700 extern u32 PicoReadM68k8(u32 a);
\r
702 addr68k=Pico.m.z80_bank68k<<15;
\r
706 ret = PicoReadM68k8(addr68k);
\r
707 else ret = PicoRead8(addr68k);
\r
708 elprintf(EL_Z80BNK, "z80->68k r8 [%06x] %02x", addr68k, ret);
\r
712 // should not be needed, cores should be able to access RAM themselves
\r
713 if (a<0x4000) return Pico.zram[a&0x1fff];
\r
715 elprintf(EL_ANOMALY, "z80 invalid r8 [%06x] %02x", a, ret);
\r
720 PICO_INTERNAL_ASM void z80_write(unsigned char data, unsigned short a)
\r
722 PICO_INTERNAL_ASM void z80_write(unsigned int a, unsigned char data)
\r
725 if ((a>>13)==2) // 0x4000-0x5fff (Charles MacDonald)
\r
727 if(PicoOpt&1) emustatus|=YM2612Write(a, data) & 1;
\r
731 if ((a&0xfff9)==0x7f11) // 7f11 7f13 7f15 7f17
\r
733 if(PicoOpt&2) SN76496Write(data);
\r
739 Pico.m.z80_bank68k>>=1;
\r
740 Pico.m.z80_bank68k|=(data&1)<<8;
\r
741 Pico.m.z80_bank68k&=0x1ff; // 9 bits and filled in the new top one
\r
747 extern void PicoWriteM68k8(u32 a,u8 d);
\r
749 addr68k=Pico.m.z80_bank68k<<15;
\r
751 elprintf(EL_Z80BNK, "z80->68k w8 [%06x] %02x", addr68k, data);
\r
753 PicoWriteM68k8(addr68k, data);
\r
754 else PicoWrite8(addr68k, data);
\r
758 // should not be needed
\r
759 if (a<0x4000) { Pico.zram[a&0x1fff]=data; return; }
\r
761 elprintf(EL_ANOMALY, "z80 invalid w8 [%06x] %02x", a, data);
\r
765 PICO_INTERNAL unsigned short z80_read16(unsigned short a)
\r
767 return (u16) ( (u16)z80_read(a) | ((u16)z80_read((u16)(a+1))<<8) );
\r
770 PICO_INTERNAL void z80_write16(unsigned short data, unsigned short a)
\r
772 z80_write((unsigned char) data,a);
\r
773 z80_write((unsigned char)(data>>8),(u16)(a+1));
\r