1 // This is part of Pico Library
\r
3 // (c) Copyright 2004 Dave, All rights reserved.
\r
4 // (c) Copyright 2006 notaz, All rights reserved.
\r
5 // Free for non-commercial use.
\r
7 // For commercial use, separate licencing terms must be obtained.
\r
12 #include "PicoInt.h"
\r
14 #include "sound/ym2612.h"
\r
15 #include "sound/sn76496.h"
\r
17 #ifndef UTYPES_DEFINED
\r
18 typedef unsigned char u8;
\r
19 typedef unsigned short u16;
\r
20 typedef unsigned int u32;
\r
21 #define UTYPES_DEFINED
\r
24 extern unsigned int lastSSRamWrite; // used by serial SRAM code
\r
26 #ifdef _ASM_MEMORY_C
\r
27 u32 PicoRead8(u32 a);
\r
28 u32 PicoRead16(u32 a);
\r
29 void PicoWrite8(u32 a,u8 d);
\r
30 void PicoWriteRomHW_SSF2(u32 a,u32 d);
\r
34 #ifdef EMU_CORE_DEBUG
\r
35 u32 lastread_a, lastread_d[16]={0,}, lastwrite_cyc_d[16]={0,}, lastwrite_mus_d[16]={0,};
\r
36 int lrp_cyc=0, lrp_mus=0, lwp_cyc=0, lwp_mus=0;
\r
37 extern unsigned int ppop;
\r
41 void log_io(unsigned int addr, int bits, int rw);
\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 static void SRAMWrite(u32 a, u32 d)
\r
156 unsigned int sreg = Pico.m.sram_reg;
\r
157 if(!(sreg & 0x10)) {
\r
158 // not detected SRAM
\r
159 if((a&~1)==0x200000) {
\r
160 elprintf(EL_SRAMIO, "eeprom detected.");
\r
161 sreg|=4; // this should be a game with EEPROM (like NBA Jam)
\r
162 SRam.start=0x200000; SRam.end=SRam.start+1;
\r
164 elprintf(EL_SRAMIO, "normal sram detected.");
\r
166 Pico.m.sram_reg=sreg;
\r
168 if(sreg & 4) { // EEPROM write
\r
169 // this diff must be at most 16 for NBA Jam to work
\r
170 if(SekCyclesDoneT()-lastSSRamWrite < 16) {
\r
171 // just update pending state
\r
172 elprintf(EL_EEPROM, "eeprom: skip because cycles=%i", SekCyclesDoneT()-lastSSRamWrite);
\r
173 SRAMUpdPending(a, d);
\r
176 SRAMWriteEEPROM(sreg>>6); // execute pending
\r
177 SRAMUpdPending(a, d);
\r
178 if ((old^Pico.m.sram_reg)&0xc0) // update time only if SDA/SCL changed
\r
179 lastSSRamWrite = SekCyclesDoneT();
\r
181 } else if(!(sreg & 2)) {
\r
182 u8 *pm=(u8 *)(SRam.data-SRam.start+a);
\r
190 // for nonstandard reads
\r
191 #ifndef _ASM_MEMORY_C
\r
194 u32 OtherRead16End(u32 a, int realsize)
\r
198 // for games with simple protection devices, discovered by Haze
\r
199 // some dumb detection is used, but that should be enough to make things work
\r
200 if ((a>>22) == 1 && Pico.romsize >= 512*1024) {
\r
201 if (*(int *)(Pico.rom+0x123e4) == 0x00550c39 && *(int *)(Pico.rom+0x123e8) == 0x00000040) { // Super Bubble Bobble (Unl) [!]
\r
202 if (a == 0x400000) { d=0x55<<8; goto end; }
\r
203 else if (a == 0x400002) { d=0x0f<<8; goto end; }
\r
205 else if (*(int *)(Pico.rom+0x008c4) == 0x66240055 && *(int *)(Pico.rom+0x008c8) == 0x00404df9) { // Smart Mouse (Unl)
\r
206 if (a == 0x400000) { d=0x55<<8; goto end; }
\r
207 else if (a == 0x400002) { d=0x0f<<8; goto end; }
\r
208 else if (a == 0x400004) { d=0xaa<<8; goto end; }
\r
209 else if (a == 0x400006) { d=0xf0<<8; goto end; }
\r
211 else if (*(int *)(Pico.rom+0x00404) == 0x00a90600 && *(int *)(Pico.rom+0x00408) == 0x6708b013) { // King of Fighters '98, The (Unl) [!]
\r
212 if (a == 0x480000 || a == 0x4800e0 || a == 0x4824a0 || a == 0x488880) { d=0xaa<<8; goto end; }
\r
213 else if (a == 0x4a8820) { d=0x0a<<8; goto end; }
\r
214 // there is also a read @ 0x4F8820 which needs 0, but that is returned in default case
\r
216 else if (*(int *)(Pico.rom+0x01b24) == 0x004013f9 && *(int *)(Pico.rom+0x01b28) == 0x00ff0000) { // Mahjong Lover (Unl) [!]
\r
217 if (a == 0x400000) { d=0x90<<8; goto end; }
\r
218 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
219 // checks the result, which is of the above one. Left it just in case.
\r
221 else if (*(int *)(Pico.rom+0x05254) == 0x0c3962d0 && *(int *)(Pico.rom+0x05258) == 0x00400055) { // Elf Wor (Unl)
\r
222 if (a == 0x400000) { d=0x55<<8; goto end; }
\r
223 else if (a == 0x400004) { d=0xc9<<8; goto end; } // this check is done if the above one fails
\r
224 else if (a == 0x400002) { d=0x0f<<8; goto end; }
\r
225 else if (a == 0x400006) { d=0x18<<8; goto end; } // similar to above
\r
227 // our default behaviour is to return whatever was last written a 0x400000-0x7fffff range (used by Squirrel King (R) [!])
\r
228 // Lion King II, The (Unl) [!] writes @ 400000 and wants to get that val @ 400002 and wites another val
\r
229 // @ 400004 which is expected @ 400006, so we really remember 2 values here
\r
230 d = Pico.m.prot_bytes[(a>>2)&1]<<8;
\r
232 else if (a == 0xa13000 && Pico.romsize >= 1024*1024) {
\r
233 if (*(int *)(Pico.rom+0xc8af0) == 0x30133013 && *(int *)(Pico.rom+0xc8af4) == 0x000f0240) { // Rockman X3 (Unl) [!]
\r
236 else if (*(int *)(Pico.rom+0x28888) == 0x07fc0000 && *(int *)(Pico.rom+0x2888c) == 0x4eb94e75) { // Bug's Life, A (Unl) [!]
\r
237 d=0x28; goto end; // does the check from RAM
\r
239 else if (*(int *)(Pico.rom+0xc8778) == 0x30133013 && *(int *)(Pico.rom+0xc877c) == 0x000f0240) { // Super Mario Bros. (Unl) [!]
\r
240 d=0x0c; goto end; // seems to be the same code as in Rockman X3 (Unl) [!]
\r
242 else if (*(int *)(Pico.rom+0xf20ec) == 0x30143013 && *(int *)(Pico.rom+0xf20f0) == 0x000f0200) { // Super Mario 2 1998 (Unl) [!]
\r
246 else if (a == 0xa13002) { // Pocket Monsters (Unl)
\r
249 else if (a == 0xa1303E) { // Pocket Monsters (Unl)
\r
252 else if (a == 0x30fe02) {
\r
253 // Virtua Racing - just for fun
\r
254 // this seems to be some flag that SVP is ready or something similar
\r
259 elprintf(EL_UIO, "strange r%i: [%06x] %04x @%06x", realsize, a&0xffffff, d, SekPc);
\r
264 //extern UINT32 mz80GetRegisterValue(void *, UINT32);
\r
266 static void OtherWrite8End(u32 a,u32 d,int realsize)
\r
269 if(a >= SRam.start && a <= SRam.end) {
\r
270 elprintf(EL_SRAMIO, "sram w8 [%06x] %02x @ %06x", a, d, SekPc);
\r
275 #ifdef _ASM_MEMORY_C
\r
276 // special ROM hardware (currently only banking and sram reg supported)
\r
277 if((a&0xfffff1) == 0xA130F1) {
\r
278 PicoWriteRomHW_SSF2(a, d); // SSF2 or SRAM
\r
282 // sram access register
\r
283 if(a == 0xA130F1) {
\r
284 elprintf(EL_SRAMIO, "sram reg=%02x", d);
\r
285 Pico.m.sram_reg &= ~3;
\r
286 Pico.m.sram_reg |= (u8)(d&3);
\r
290 elprintf(EL_UIO, "strange w%i: %06x, %08x @%06x", realsize, a&0xffffff, d, SekPc);
\r
292 if(a >= 0xA13004 && a < 0xA13040) {
\r
293 // dumb 12-in-1 or 4-in-1 banking support
\r
295 a &= 0x3f; a <<= 16;
\r
296 len = Pico.romsize - a;
\r
297 if (len <= 0) return; // invalid/missing bank
\r
298 if (len > 0x200000) len = 0x200000; // 2 megs
\r
299 memcpy(Pico.rom, Pico.rom+a, len); // code which does this is in RAM so this is safe.
\r
303 // for games with simple protection devices, discovered by Haze
\r
304 else if ((a>>22) == 1)
\r
305 Pico.m.prot_bytes[(a>>2)&1] = (u8)d;
\r
309 #include "MemoryCmn.c"
\r
312 // -----------------------------------------------------------------
\r
313 // Read Rom and read Ram
\r
315 #ifndef _ASM_MEMORY_C
\r
316 PICO_INTERNAL_ASM u32 PicoRead8(u32 a)
\r
320 if ((a&0xe00000)==0xe00000) { d = *(u8 *)(Pico.ram+((a^1)&0xffff)); goto end; } // Ram
\r
324 #ifndef EMU_CORE_DEBUG
\r
326 if(a >= SRam.start && a <= SRam.end && (Pico.m.sram_reg&5)) {
\r
328 elprintf(EL_SRAMIO, "sram r8 [%06x] %02x @ %06x", a, d, SekPc);
\r
333 if (a<Pico.romsize) { d = *(u8 *)(Pico.rom+(a^1)); goto end; } // Rom
\r
335 if ((a&0xff4000)==0xa00000) { d=z80Read8(a); goto end; } // Z80 Ram
\r
337 d=OtherRead16(a&~1, 8); if ((a&1)==0) d>>=8;
\r
341 dprintf("r8 : %06x, %02x @%06x", a&0xffffff, (u8)d, SekPc);
\r
343 #ifdef EMU_CORE_DEBUG
\r
344 if(a>=Pico.romsize/*&&(ppop&0x3f)!=0x3a&&(ppop&0x3f)!=0x3b*/) {
\r
346 lastread_d[lrp_cyc++&15] = (u8)d;
\r
352 PICO_INTERNAL_ASM u32 PicoRead16(u32 a)
\r
356 if ((a&0xe00000)==0xe00000) { d=*(u16 *)(Pico.ram+(a&0xfffe)); goto end; } // Ram
\r
360 #ifndef EMU_CORE_DEBUG
\r
362 if(a >= SRam.start && a <= SRam.end && (Pico.m.sram_reg&5)) {
\r
365 elprintf(EL_SRAMIO, "sram r16 [%06x] %04x @ %06x", a, d, SekPc);
\r
370 if (a<Pico.romsize) { d = *(u16 *)(Pico.rom+a); goto end; } // Rom
\r
373 d = OtherRead16(a, 16);
\r
377 dprintf("r16: %06x, %04x @%06x", a&0xffffff, d, SekPc);
\r
379 #ifdef EMU_CORE_DEBUG
\r
380 if(a>=Pico.romsize/*&&(ppop&0x3f)!=0x3a&&(ppop&0x3f)!=0x3b*/) {
\r
382 lastread_d[lrp_cyc++&15] = d;
\r
388 PICO_INTERNAL_ASM u32 PicoRead32(u32 a)
\r
392 if ((a&0xe00000)==0xe00000) { u16 *pm=(u16 *)(Pico.ram+(a&0xfffe)); d = (pm[0]<<16)|pm[1]; goto end; } // Ram
\r
397 if(a >= SRam.start && a <= SRam.end && (Pico.m.sram_reg&5)) {
\r
398 d = (SRAMRead(a)<<16)|SRAMRead(a+2);
\r
400 elprintf(EL_SRAMIO, "sram r32 [%06x] %08x @ %06x", a, d, SekPc);
\r
404 if (a<Pico.romsize) { u16 *pm=(u16 *)(Pico.rom+a); d = (pm[0]<<16)|pm[1]; goto end; } // Rom
\r
407 d = (OtherRead16(a, 32)<<16)|OtherRead16(a+2, 32);
\r
411 dprintf("r32: %06x, %08x @%06x", a&0xffffff, d, SekPc);
\r
413 #ifdef EMU_CORE_DEBUG
\r
414 if(a>=Pico.romsize/*&&(ppop&0x3f)!=0x3a&&(ppop&0x3f)!=0x3b*/) {
\r
416 lastread_d[lrp_cyc++&15] = d;
\r
423 // -----------------------------------------------------------------
\r
426 #if !defined(_ASM_MEMORY_C) || defined(_ASM_MEMORY_C_AMIPS)
\r
427 PICO_INTERNAL_ASM void PicoWrite8(u32 a,u8 d)
\r
430 dprintf("w8 : %06x, %02x @%06x", a&0xffffff, d, SekPc);
\r
432 #ifdef EMU_CORE_DEBUG
\r
433 lastwrite_cyc_d[lwp_cyc++&15] = d;
\r
436 if ((a&0xe00000)==0xe00000) { *(u8 *)(Pico.ram+((a^1)&0xffff))=d; return; } // Ram
\r
444 void PicoWrite16(u32 a,u16 d)
\r
447 dprintf("w16: %06x, %04x", a&0xffffff, d);
\r
449 #ifdef EMU_CORE_DEBUG
\r
450 lastwrite_cyc_d[lwp_cyc++&15] = d;
\r
453 if ((a&0xe00000)==0xe00000) { *(u16 *)(Pico.ram+(a&0xfffe))=d; return; } // Ram
\r
460 static void PicoWrite32(u32 a,u32 d)
\r
463 dprintf("w32: %06x, %08x", a&0xffffff, d);
\r
465 #ifdef EMU_CORE_DEBUG
\r
466 lastwrite_cyc_d[lwp_cyc++&15] = d;
\r
469 if ((a&0xe00000)==0xe00000)
\r
472 u16 *pm=(u16 *)(Pico.ram+(a&0xfffe));
\r
473 pm[0]=(u16)(d>>16); pm[1]=(u16)d;
\r
479 OtherWrite16(a, (u16)(d>>16));
\r
480 OtherWrite16(a+2,(u16)d);
\r
484 // -----------------------------------------------------------------
\r
485 PICO_INTERNAL void PicoMemSetup(void)
\r
487 // Setup memory callbacks:
\r
489 PicoCpuCM68k.checkpc=PicoCheckPc;
\r
490 PicoCpuCM68k.fetch8 =PicoCpuCM68k.read8 =PicoRead8;
\r
491 PicoCpuCM68k.fetch16=PicoCpuCM68k.read16=PicoRead16;
\r
492 PicoCpuCM68k.fetch32=PicoCpuCM68k.read32=PicoRead32;
\r
493 PicoCpuCM68k.write8 =PicoWrite8;
\r
494 PicoCpuCM68k.write16=PicoWrite16;
\r
495 PicoCpuCM68k.write32=PicoWrite32;
\r
498 PicoCpuFM68k.read_byte =PicoRead8;
\r
499 PicoCpuFM68k.read_word =PicoRead16;
\r
500 PicoCpuFM68k.read_long =PicoRead32;
\r
501 PicoCpuFM68k.write_byte=PicoWrite8;
\r
502 PicoCpuFM68k.write_word=PicoWrite16;
\r
503 PicoCpuFM68k.write_long=PicoWrite32;
\r
505 // setup FAME fetchmap
\r
508 // by default, point everything to fitst 64k of ROM
\r
509 for (i = 0; i < M68K_FETCHBANK1; i++)
\r
510 PicoCpuFM68k.Fetch[i] = (unsigned int)Pico.rom - (i<<(24-FAMEC_FETCHBITS));
\r
512 for (i = 0; i < M68K_FETCHBANK1 && (i<<(24-FAMEC_FETCHBITS)) < Pico.romsize; i++)
\r
513 PicoCpuFM68k.Fetch[i] = (unsigned int)Pico.rom;
\r
515 for (i = M68K_FETCHBANK1*14/16; i < M68K_FETCHBANK1; i++)
\r
516 PicoCpuFM68k.Fetch[i] = (unsigned int)Pico.ram - (i<<(24-FAMEC_FETCHBITS));
\r
523 unsigned int m68k_read_pcrelative_CD8 (unsigned int a);
\r
524 unsigned int m68k_read_pcrelative_CD16(unsigned int a);
\r
525 unsigned int m68k_read_pcrelative_CD32(unsigned int a);
\r
527 // these are allowed to access RAM
\r
528 static unsigned int m68k_read_8 (unsigned int a, int do_fake) {
\r
530 if(PicoMCD&1) return m68k_read_pcrelative_CD8(a);
\r
531 if(a<Pico.romsize) return *(u8 *)(Pico.rom+(a^1)); // Rom
\r
532 #ifdef EMU_CORE_DEBUG
\r
533 if(do_fake&&((ppop&0x3f)==0x3a||(ppop&0x3f)==0x3b)) return lastread_d[lrp_mus++&15];
\r
535 if((a&0xe00000)==0xe00000) return *(u8 *)(Pico.ram+((a^1)&0xffff)); // Ram
\r
538 static unsigned int m68k_read_16(unsigned int a, int do_fake) {
\r
540 if(PicoMCD&1) return m68k_read_pcrelative_CD16(a);
\r
541 if(a<Pico.romsize) return *(u16 *)(Pico.rom+(a&~1)); // Rom
\r
542 #ifdef EMU_CORE_DEBUG
\r
543 if(do_fake&&((ppop&0x3f)==0x3a||(ppop&0x3f)==0x3b)) return lastread_d[lrp_mus++&15];
\r
545 if((a&0xe00000)==0xe00000) return *(u16 *)(Pico.ram+(a&0xfffe)); // Ram
\r
548 static unsigned int m68k_read_32(unsigned int a, int do_fake) {
\r
550 if(PicoMCD&1) return m68k_read_pcrelative_CD32(a);
\r
551 if(a<Pico.romsize) { u16 *pm=(u16 *)(Pico.rom+(a&~1)); return (pm[0]<<16)|pm[1]; }
\r
552 #ifdef EMU_CORE_DEBUG
\r
553 if(do_fake&&((ppop&0x3f)==0x3a||(ppop&0x3f)==0x3b)) return lastread_d[lrp_mus++&15];
\r
555 if((a&0xe00000)==0xe00000) { u16 *pm=(u16 *)(Pico.ram+(a&0xfffe)); return (pm[0]<<16)|pm[1]; } // Ram
\r
559 unsigned int m68k_read_pcrelative_8 (unsigned int a) { return m68k_read_8 (a, 1); }
\r
560 unsigned int m68k_read_pcrelative_16(unsigned int a) { return m68k_read_16(a, 1); }
\r
561 unsigned int m68k_read_pcrelative_32(unsigned int a) { return m68k_read_32(a, 1); }
\r
562 unsigned int m68k_read_immediate_16(unsigned int a) { return m68k_read_16(a, 0); }
\r
563 unsigned int m68k_read_immediate_32(unsigned int a) { return m68k_read_32(a, 0); }
\r
564 unsigned int m68k_read_disassembler_8 (unsigned int a) { return m68k_read_8 (a, 0); }
\r
565 unsigned int m68k_read_disassembler_16(unsigned int a) { return m68k_read_16(a, 0); }
\r
566 unsigned int m68k_read_disassembler_32(unsigned int a) { return m68k_read_32(a, 0); }
\r
568 #ifdef EMU_CORE_DEBUG
\r
570 unsigned int m68k_read_memory_8(unsigned int a)
\r
573 if(a<Pico.romsize) d = *(u8 *) (Pico.rom+(a^1));
\r
574 else d = (u8) lastread_d[lrp_mus++&15];
\r
576 dprintf("r8_mu : %06x, %02x @%06x", a&0xffffff, d, SekPc);
\r
580 unsigned int m68k_read_memory_16(unsigned int a)
\r
583 if(a<Pico.romsize) d = *(u16 *)(Pico.rom+(a&~1));
\r
584 else d = (u16) lastread_d[lrp_mus++&15];
\r
586 dprintf("r16_mu: %06x, %04x @%06x", a&0xffffff, d, SekPc);
\r
590 unsigned int m68k_read_memory_32(unsigned int a)
\r
593 if(a<Pico.romsize) {u16 *pm=(u16 *)(Pico.rom+(a&~1));d=(pm[0]<<16)|pm[1];}
\r
594 else d = lastread_d[lrp_mus++&15];
\r
596 dprintf("r32_mu: %06x, %08x @%06x", a&0xffffff, d, SekPc);
\r
601 // ignore writes, Cyclone already done that
\r
602 void m68k_write_memory_8(unsigned int address, unsigned int value) { lastwrite_mus_d[lwp_mus++&15] = value; }
\r
603 void m68k_write_memory_16(unsigned int address, unsigned int value) { lastwrite_mus_d[lwp_mus++&15] = value; }
\r
604 void m68k_write_memory_32(unsigned int address, unsigned int value) { lastwrite_mus_d[lwp_mus++&15] = value; }
\r
606 unsigned char PicoReadCD8w (unsigned int a);
\r
607 unsigned short PicoReadCD16w(unsigned int a);
\r
608 unsigned int PicoReadCD32w(unsigned int a);
\r
609 void PicoWriteCD8w (unsigned int a, unsigned char d);
\r
610 void PicoWriteCD16w(unsigned int a, unsigned short d);
\r
611 void PicoWriteCD32w(unsigned int a, unsigned int d);
\r
613 /* it appears that Musashi doesn't always mask the unused bits */
\r
614 unsigned int m68k_read_memory_8(unsigned int address)
\r
616 unsigned int d = (PicoMCD&1) ? PicoReadCD8w(address) : PicoRead8(address);
\r
620 unsigned int m68k_read_memory_16(unsigned int address)
\r
622 unsigned int d = (PicoMCD&1) ? PicoReadCD16w(address) : PicoRead16(address);
\r
626 unsigned int m68k_read_memory_32(unsigned int address)
\r
628 return (PicoMCD&1) ? PicoReadCD32w(address) : PicoRead32(address);
\r
631 void m68k_write_memory_8(unsigned int address, unsigned int value)
\r
633 if (PicoMCD&1) PicoWriteCD8w(address, (u8)value); else PicoWrite8(address, (u8)value);
\r
636 void m68k_write_memory_16(unsigned int address, unsigned int value)
\r
638 if (PicoMCD&1) PicoWriteCD16w(address,(u16)value); else PicoWrite16(address,(u16)value);
\r
641 void m68k_write_memory_32(unsigned int address, unsigned int value)
\r
643 if (PicoMCD&1) PicoWriteCD32w(address, value); else PicoWrite32(address, value);
\r
649 // -----------------------------------------------------------------
\r
652 PICO_INTERNAL unsigned char z80_read(unsigned short a)
\r
657 if (a<0x4000) return Pico.zram[a&0x1fff];
\r
660 if ((a>>13)==2) // 0x4000-0x5fff (Charles MacDonald)
\r
662 if (PicoOpt&1) ret = (u8) YM2612Read();
\r
669 addr68k=Pico.m.z80_bank68k<<15;
\r
672 ret = (u8) PicoRead8(addr68k);
\r
673 elprintf(EL_Z80BNK, "z80->68k r8 [%06x] %02x", addr68k, ret);
\r
678 // should not be needed || dprintf("z80_read RAM");
\r
679 if (a<0x4000) return Pico.zram[a&0x1fff];
\r
682 elprintf(EL_ANOMALY, "z80 invalid r8 [%06x] %02x", a, ret);
\r
687 PICO_INTERNAL_ASM void z80_write(unsigned char data, unsigned short a)
\r
689 PICO_INTERNAL_ASM void z80_write(unsigned int a, unsigned char data)
\r
693 if (a<0x4000) { Pico.zram[a&0x1fff]=data; return; }
\r
696 if ((a>>13)==2) // 0x4000-0x5fff (Charles MacDonald)
\r
698 if(PicoOpt&1) emustatus|=YM2612Write(a, data) & 1;
\r
702 if ((a&0xfff9)==0x7f11) // 7f11 7f13 7f15 7f17
\r
704 if(PicoOpt&2) SN76496Write(data);
\r
710 Pico.m.z80_bank68k>>=1;
\r
711 Pico.m.z80_bank68k|=(data&1)<<8;
\r
712 Pico.m.z80_bank68k&=0x1ff; // 9 bits and filled in the new top one
\r
719 addr68k=Pico.m.z80_bank68k<<15;
\r
721 elprintf(EL_Z80BNK, "z80->68k w8 [%06x] %02x", addr68k, data);
\r
722 PicoWrite8(addr68k, data);
\r
727 // should not be needed, drZ80 knows how to access RAM itself || dprintf("z80_write RAM @ %08x", lr);
\r
728 if (a<0x4000) { Pico.zram[a&0x1fff]=data; return; }
\r
731 elprintf(EL_ANOMALY, "z80 invalid w8 [%06x] %02x", a, data);
\r
735 PICO_INTERNAL unsigned short z80_read16(unsigned short a)
\r
737 return (u16) ( (u16)z80_read(a) | ((u16)z80_read((u16)(a+1))<<8) );
\r
740 PICO_INTERNAL void z80_write16(unsigned short data, unsigned short a)
\r
742 z80_write((unsigned char) data,a);
\r
743 z80_write((unsigned char)(data>>8),(u16)(a+1));
\r