1 // Memory I/O handlers for Sega/Mega CD.
\r
2 // Loosely based on Gens code.
\r
3 // (c) Copyright 2007, Grazvydas "notaz" Ignotas
\r
6 #include "../PicoInt.h"
\r
8 #include "../sound/ym2612.h"
\r
9 #include "../sound/sn76496.h"
\r
14 #ifndef UTYPES_DEFINED
\r
15 typedef unsigned char u8;
\r
16 typedef unsigned short u16;
\r
17 typedef unsigned int u32;
\r
18 #define UTYPES_DEFINED
\r
25 //#define rdprintf dprintf
\r
26 #define rdprintf(...)
\r
27 //#define wrdprintf dprintf
\r
28 #define wrdprintf(...)
\r
31 #ifdef EMU_CORE_DEBUG
\r
32 extern u32 lastread_a, lastread_d[16], lastwrite_cyc_d[16];
\r
33 extern int lrp_cyc, lwp_cyc;
\r
34 #undef USE_POLL_DETECT
\r
37 // -----------------------------------------------------------------
\r
40 #define POLL_LIMIT 16
\r
41 #define POLL_CYCLES 124
\r
42 // int m68k_poll_addr, m68k_poll_cnt;
\r
43 unsigned int s68k_poll_adclk, s68k_poll_cnt;
\r
45 #ifndef _ASM_CD_MEMORY_C
\r
46 static u32 m68k_reg_read16(u32 a)
\r
50 // dprintf("m68k_regs r%2i: [%02x] @%06x", realsize&~1, a+(realsize&1), SekPc);
\r
54 d = ((Pico_mcd->s68k_regs[0x33]<<13)&0x8000) | Pico_mcd->m.busreq; // here IFL2 is always 0, just like in Gens
\r
57 d = (Pico_mcd->s68k_regs[a]<<8) | (Pico_mcd->s68k_regs[a+1]&0xc7);
\r
58 // the DMNA delay must only be visible on s68k side (Lunar2, Silpheed)
\r
59 if (Pico_mcd->m.state_flags&2) { d &= ~1; d |= 2; }
\r
60 //printf("m68k_regs r3: %02x @%06x\n", (u8)d, SekPc);
\r
63 d = Pico_mcd->s68k_regs[4]<<8;
\r
66 d = *(u16 *)(Pico_mcd->bios + 0x72);
\r
69 d = Read_CDC_Host(0);
\r
72 elprintf(EL_UIO, "m68k FIXME: reserved read");
\r
75 d = Pico_mcd->m.timer_stopwatch >> 16;
\r
76 dprintf("m68k stopwatch timer read (%04x)", d);
\r
81 // comm flag/cmd/status (0xE-0x2F)
\r
82 d = (Pico_mcd->s68k_regs[a]<<8) | Pico_mcd->s68k_regs[a+1];
\r
86 elprintf(EL_UIO, "m68k_regs FIXME invalid read @ %02x", a);
\r
94 #ifndef _ASM_CD_MEMORY_C
\r
97 void m68k_reg_write8(u32 a, u32 d)
\r
100 // dprintf("m68k_regs w%2i: [%02x] %02x @%06x", realsize, a, d, SekPc);
\r
105 if ((d&1) && (Pico_mcd->s68k_regs[0x33]&(1<<2))) { elprintf(EL_INTS, "m68k: s68k irq 2"); SekInterruptS68k(2); }
\r
109 if (!(d&1)) Pico_mcd->m.state_flags |= 1; // reset pending, needed to be sure we fetch the right vectors on reset
\r
110 if ( (Pico_mcd->m.busreq&1) != (d&1)) dprintf("m68k: s68k reset %i", !(d&1));
\r
111 if ( (Pico_mcd->m.busreq&2) != (d&2)) dprintf("m68k: s68k brq %i", (d&2)>>1);
\r
112 if ((Pico_mcd->m.state_flags&1) && (d&3)==1) {
\r
113 SekResetS68k(); // S68k comes out of RESET or BRQ state
\r
114 Pico_mcd->m.state_flags&=~1;
\r
115 dprintf("m68k: resetting s68k, cycles=%i", SekCyclesLeft);
\r
117 Pico_mcd->m.busreq = d;
\r
120 dprintf("m68k: prg wp=%02x", d);
\r
121 Pico_mcd->s68k_regs[2] = d; // really use s68k side register
\r
124 u32 dold = Pico_mcd->s68k_regs[3]&0x1f;
\r
125 //printf("m68k_regs w3: %02x @%06x\n", (u8)d, SekPc);
\r
127 if ((dold>>6) != ((d>>6)&3))
\r
128 dprintf("m68k: prg bank: %i -> %i", (Pico_mcd->s68k_regs[a]>>6), ((d>>6)&3));
\r
129 //if ((Pico_mcd->s68k_regs[3]&4) != (d&4)) dprintf("m68k: ram mode %i mbit", (d&4) ? 1 : 2);
\r
130 //if ((Pico_mcd->s68k_regs[3]&2) != (d&2)) dprintf("m68k: %s", (d&4) ? ((d&2) ? "word swap req" : "noop?") :
\r
131 // ((d&2) ? "word ram to s68k" : "word ram to m68k"));
\r
133 d ^= 2; // writing 0 to DMNA actually sets it, 1 does nothing
\r
135 //dold &= ~2; // ??
\r
137 if ((d & 2) && !(dold & 2)) {
\r
138 Pico_mcd->m.state_flags |= 2; // we must delay setting DMNA bit (needed for Silpheed)
\r
142 if (d & 2) dold &= ~1; // return word RAM to s68k in 2M mode
\r
145 Pico_mcd->s68k_regs[3] = d | dold; // really use s68k side register
\r
146 #ifdef USE_POLL_DETECT
\r
147 if ((s68k_poll_adclk&0xfe) == 2 && s68k_poll_cnt > POLL_LIMIT) {
\r
148 SekSetStopS68k(0); s68k_poll_adclk = 0;
\r
149 elprintf(EL_CDPOLL, "s68k poll release, a=%02x", a);
\r
155 Pico_mcd->bios[0x72 + 1] = d; // simple hint vector changer
\r
158 Pico_mcd->bios[0x72] = d;
\r
159 dprintf("hint vector set to %08x", PicoRead32(0x70));
\r
162 d = (d << 1) | ((d >> 7) & 1); // rol8 1 (special case)
\r
164 //dprintf("m68k: comm flag: %02x", d);
\r
165 Pico_mcd->s68k_regs[0xe] = d;
\r
166 #ifdef USE_POLL_DETECT
\r
167 if ((s68k_poll_adclk&0xfe) == 0xe && s68k_poll_cnt > POLL_LIMIT) {
\r
168 SekSetStopS68k(0); s68k_poll_adclk = 0;
\r
169 elprintf(EL_CDPOLL, "s68k poll release, a=%02x", a);
\r
175 if ((a&0xf0) == 0x10) {
\r
176 Pico_mcd->s68k_regs[a] = d;
\r
177 #ifdef USE_POLL_DETECT
\r
178 if ((a&0xfe) == (s68k_poll_adclk&0xfe) && s68k_poll_cnt > POLL_LIMIT) {
\r
179 SekSetStopS68k(0); s68k_poll_adclk = 0;
\r
180 elprintf(EL_CDPOLL, "s68k poll release, a=%02x", a);
\r
186 elprintf(EL_UIO, "m68k FIXME: invalid write? [%02x] %02x", a, d);
\r
189 #ifndef _ASM_CD_MEMORY_C
\r
192 u32 s68k_poll_detect(u32 a, u32 d)
\r
194 #ifdef USE_POLL_DETECT
\r
195 // needed mostly for Cyclone, which doesn't always check it's cycle counter
\r
196 if (SekIsStoppedS68k()) return d;
\r
197 // polling detection
\r
198 if (a == (s68k_poll_adclk&0xff)) {
\r
199 unsigned int clkdiff = SekCyclesDoneS68k() - (s68k_poll_adclk>>8);
\r
200 if (clkdiff <= POLL_CYCLES) {
\r
202 //printf("-- diff: %u, cnt = %i\n", clkdiff, s68k_poll_cnt);
\r
203 if (s68k_poll_cnt > POLL_LIMIT) {
\r
205 elprintf(EL_CDPOLL, "s68k poll detected @ %06x, a=%02x", SekPcS68k, a);
\r
207 s68k_poll_adclk = (SekCyclesDoneS68k() << 8) | a;
\r
211 s68k_poll_adclk = (SekCyclesDoneS68k() << 8) | a;
\r
217 #define READ_FONT_DATA(basemask) \
\r
219 unsigned int fnt = *(unsigned int *)(Pico_mcd->s68k_regs + 0x4c); \
\r
220 unsigned int col0 = (fnt >> 8) & 0x0f, col1 = (fnt >> 12) & 0x0f; \
\r
221 if (fnt & (basemask << 0)) d = col1 ; else d = col0; \
\r
222 if (fnt & (basemask << 1)) d |= col1 << 4; else d |= col0 << 4; \
\r
223 if (fnt & (basemask << 2)) d |= col1 << 8; else d |= col0 << 8; \
\r
224 if (fnt & (basemask << 3)) d |= col1 << 12; else d |= col0 << 12; \
\r
228 #ifndef _ASM_CD_MEMORY_C
\r
231 u32 s68k_reg_read16(u32 a)
\r
235 // dprintf("s68k_regs r%2i: [%02x] @ %06x", realsize&~1, a+(realsize&1), SekPcS68k);
\r
239 return ((Pico_mcd->s68k_regs[0]&3)<<8) | 1; // ver = 0, not in reset state
\r
241 d = (Pico_mcd->s68k_regs[2]<<8) | (Pico_mcd->s68k_regs[3]&0x1f);
\r
242 //printf("s68k_regs r3: %02x @%06x\n", (u8)d, SekPcS68k);
\r
243 return s68k_poll_detect(a, d);
\r
245 return CDC_Read_Reg();
\r
247 return Read_CDC_Host(1); // Gens returns 0 here on byte reads
\r
249 d = Pico_mcd->m.timer_stopwatch >> 16;
\r
250 dprintf("s68k stopwatch timer read (%04x)", d);
\r
253 dprintf("s68k int3 timer read (%02x)", Pico_mcd->s68k_regs[31]);
\r
254 return Pico_mcd->s68k_regs[31];
\r
255 case 0x34: // fader
\r
256 return 0; // no busy bit
\r
257 case 0x50: // font data (check: Lunar 2, Silpheed)
\r
258 READ_FONT_DATA(0x00100000);
\r
261 READ_FONT_DATA(0x00010000);
\r
264 READ_FONT_DATA(0x10000000);
\r
267 READ_FONT_DATA(0x01000000);
\r
271 d = (Pico_mcd->s68k_regs[a]<<8) | Pico_mcd->s68k_regs[a+1];
\r
273 if (a >= 0x0e && a < 0x30)
\r
274 return s68k_poll_detect(a, d);
\r
279 #ifndef _ASM_CD_MEMORY_C
\r
282 void s68k_reg_write8(u32 a, u32 d)
\r
284 //dprintf("s68k_regs w%2i: [%02x] %02x @ %06x", realsize, a, d, SekPcS68k);
\r
286 // Warning: d might have upper bits set
\r
289 return; // only m68k can change WP
\r
291 int dold = Pico_mcd->s68k_regs[3];
\r
292 //printf("s68k_regs w3: %02x @%06x\n", (u8)d, SekPcS68k);
\r
296 if ((d ^ dold) & 5) {
\r
297 d &= ~2; // in case of mode or bank change we clear DMNA (m68k req) bit
\r
300 #ifdef _ASM_CD_MEMORY_C
\r
301 if ((d ^ dold) & 0x1d)
\r
302 PicoMemResetCDdecode(d);
\r
305 dprintf("wram mode 2M->1M");
\r
306 wram_2M_to_1M(Pico_mcd->word_ram2M);
\r
310 dprintf("wram mode 1M->2M");
\r
311 if (!(d&1)) { // it didn't set the ret bit, which means it doesn't want to give WRAM to m68k
\r
313 d |= (dold&1) ? 2 : 1; // then give it to the one which had bank0 in 1M mode
\r
315 wram_1M_to_2M(Pico_mcd->word_ram2M);
\r
320 if (d&1) d &= ~2; // return word RAM to m68k in 2M mode
\r
325 dprintf("s68k CDC dest: %x", d&7);
\r
326 Pico_mcd->s68k_regs[4] = (Pico_mcd->s68k_regs[4]&0xC0) | (d&7); // CDC mode
\r
329 //dprintf("s68k CDC reg addr: %x", d&0xf);
\r
335 dprintf("s68k set CDC dma addr");
\r
339 dprintf("s68k set stopwatch timer");
\r
340 Pico_mcd->m.timer_stopwatch = 0;
\r
343 Pico_mcd->s68k_regs[0xf] = (d>>1) | (d<<7); // ror8 1, Gens note: Dragons lair
\r
346 dprintf("s68k set int3 timer: %02x", d);
\r
347 Pico_mcd->m.timer_int3 = (d & 0xff) << 16;
\r
349 case 0x33: // IRQ mask
\r
350 dprintf("s68k irq mask: %02x", d);
\r
351 if ((d&(1<<4)) && (Pico_mcd->s68k_regs[0x37]&4) && !(Pico_mcd->s68k_regs[0x33]&(1<<4))) {
\r
352 CDD_Export_Status();
\r
355 case 0x34: // fader
\r
356 Pico_mcd->s68k_regs[a] = (u8) d & 0x7f;
\r
359 return; // d/m bit is unsetable
\r
361 u32 d_old = Pico_mcd->s68k_regs[0x37];
\r
362 Pico_mcd->s68k_regs[0x37] = d&7;
\r
363 if ((d&4) && !(d_old&4)) {
\r
364 CDD_Export_Status();
\r
369 Pico_mcd->s68k_regs[a] = (u8) d;
\r
370 CDD_Import_Command();
\r
374 if ((a&0x1f0) == 0x10 || (a >= 0x38 && a < 0x42))
\r
376 elprintf(EL_UIO, "s68k FIXME: invalid write @ %02x?", a);
\r
380 Pico_mcd->s68k_regs[a] = (u8) d;
\r
384 static u32 OtherRead16End(u32 a, int realsize)
\r
388 #ifndef _ASM_CD_MEMORY_C
\r
389 if ((a&0xffffc0)==0xa12000) {
\r
390 d=m68k_reg_read16(a);
\r
395 if (SRam.data != NULL) d=3; // 64k cart
\r
399 if ((a&0xfe0000)==0x600000) {
\r
400 if (SRam.data != NULL) {
\r
401 d=SRam.data[((a>>1)&0xffff)+0x2000];
\r
402 if (realsize == 8) d|=d<<8;
\r
408 d=Pico_mcd->m.bcram_reg;
\r
413 elprintf(EL_UIO, "m68k FIXME: unusual r%i: %06x @%06x", realsize&~1, (a&0xfffffe)+(realsize&1), SekPc);
\r
415 #ifndef _ASM_CD_MEMORY_C
\r
422 static void OtherWrite8End(u32 a, u32 d, int realsize)
\r
424 #ifndef _ASM_CD_MEMORY_C
\r
425 if ((a&0xffffc0)==0xa12000) { m68k_reg_write8(a, d); return; }
\r
427 if ((a&0xfe0000)==0x600000) {
\r
428 if (SRam.data != NULL && (Pico_mcd->m.bcram_reg&1)) {
\r
429 SRam.data[((a>>1)&0xffff)+0x2000]=d;
\r
436 Pico_mcd->m.bcram_reg=d;
\r
441 elprintf(EL_UIO, "m68k FIXME: strange w%i: [%06x], %08x @%06x", realsize, a&0xffffff, d, SekPc);
\r
444 #ifndef _ASM_CD_MEMORY_C
\r
445 #define _CD_MEMORY_C
\r
446 #undef _ASM_MEMORY_C
\r
447 #include "../MemoryCmn.c"
\r
448 #include "cell_map.c"
\r
452 // -----------------------------------------------------------------
\r
453 // Read Rom and read Ram
\r
455 #ifdef _ASM_CD_MEMORY_C
\r
456 u32 PicoReadM68k8(u32 a);
\r
458 u32 PicoReadM68k8(u32 a)
\r
466 case 0x00>>1: // BIOS: 000000 - 020000
\r
467 d = *(u8 *)(Pico_mcd->bios+(a^1));
\r
469 case 0x02>>1: // prg RAM
\r
470 if ((Pico_mcd->m.busreq&3)!=1) {
\r
471 u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6];
\r
472 d = *(prg_bank+((a^1)&0x1ffff));
\r
475 case 0x20>>1: // word RAM: 200000 - 220000
\r
476 wrdprintf("m68k_wram r8: [%06x] @%06x", a, SekPc);
\r
478 if (Pico_mcd->s68k_regs[3]&4) { // 1M mode?
\r
479 int bank = Pico_mcd->s68k_regs[3]&1;
\r
480 d = Pico_mcd->word_ram1M[bank][a^1];
\r
482 // allow access in any mode, like Gens does
\r
483 d = Pico_mcd->word_ram2M[a^1];
\r
485 wrdprintf("ret = %02x", (u8)d);
\r
487 case 0x22>>1: // word RAM: 220000 - 240000
\r
488 wrdprintf("m68k_wram r8: [%06x] @%06x", a, SekPc);
\r
489 if (Pico_mcd->s68k_regs[3]&4) { // 1M mode?
\r
490 int bank = Pico_mcd->s68k_regs[3]&1;
\r
491 a = (a&3) | (cell_map(a >> 2) << 2); // cell arranged
\r
492 d = Pico_mcd->word_ram1M[bank][a^1];
\r
494 // allow access in any mode, like Gens does
\r
495 d = Pico_mcd->word_ram2M[(a^1)&0x3ffff];
\r
497 wrdprintf("ret = %02x", (u8)d);
\r
499 case 0xc0>>1: case 0xc2>>1: case 0xc4>>1: case 0xc6>>1:
\r
500 case 0xc8>>1: case 0xca>>1: case 0xcc>>1: case 0xce>>1:
\r
501 case 0xd0>>1: case 0xd2>>1: case 0xd4>>1: case 0xd6>>1:
\r
502 case 0xd8>>1: case 0xda>>1: case 0xdc>>1: case 0xde>>1:
\r
504 if ((a&0xe700e0)==0xc00000) {
\r
505 d=PicoVideoRead(a);
\r
506 if ((a&1)==0) d>>=8;
\r
509 case 0xe0>>1: case 0xe2>>1: case 0xe4>>1: case 0xe6>>1:
\r
510 case 0xe8>>1: case 0xea>>1: case 0xec>>1: case 0xee>>1:
\r
511 case 0xf0>>1: case 0xf2>>1: case 0xf4>>1: case 0xf6>>1:
\r
512 case 0xf8>>1: case 0xfa>>1: case 0xfc>>1: case 0xfe>>1:
\r
514 d = *(u8 *)(Pico.ram+((a^1)&0xffff));
\r
517 if ((a&0xff4000)==0xa00000) { d=z80Read8(a); break; } // Z80 Ram
\r
518 if ((a&0xffffc0)==0xa12000)
\r
519 rdprintf("m68k_regs r8: [%02x] @%06x", a&0x3f, SekPc);
\r
521 d=OtherRead16(a&~1, 8|(a&1)); if ((a&1)==0) d>>=8;
\r
523 if ((a&0xffffc0)==0xa12000)
\r
524 rdprintf("ret = %02x", (u8)d);
\r
529 elprintf(EL_IO, "r8 : %06x, %02x @%06x", a&0xffffff, (u8)d, SekPc);
\r
530 #ifdef EMU_CORE_DEBUG
\r
531 if (a>=Pico.romsize) {
\r
533 lastread_d[lrp_cyc++&15] = d;
\r
541 #ifdef _ASM_CD_MEMORY_C
\r
542 u32 PicoReadM68k16(u32 a);
\r
544 static u32 PicoReadM68k16(u32 a)
\r
552 case 0x00>>1: // BIOS: 000000 - 020000
\r
553 d = *(u16 *)(Pico_mcd->bios+a);
\r
555 case 0x02>>1: // prg RAM
\r
556 if ((Pico_mcd->m.busreq&3)!=1) {
\r
557 u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6];
\r
558 wrdprintf("m68k_prgram r16: [%i,%06x] @%06x", Pico_mcd->s68k_regs[3]>>6, a, SekPc);
\r
559 d = *(u16 *)(prg_bank+(a&0x1fffe));
\r
560 wrdprintf("ret = %04x", d);
\r
563 case 0x20>>1: // word RAM: 200000 - 220000
\r
564 wrdprintf("m68k_wram r16: [%06x] @%06x", a, SekPc);
\r
566 if (Pico_mcd->s68k_regs[3]&4) { // 1M mode?
\r
567 int bank = Pico_mcd->s68k_regs[3]&1;
\r
568 d = *(u16 *)(Pico_mcd->word_ram1M[bank]+a);
\r
570 // allow access in any mode, like Gens does
\r
571 d = *(u16 *)(Pico_mcd->word_ram2M+a);
\r
573 wrdprintf("ret = %04x", d);
\r
575 case 0x22>>1: // word RAM: 220000 - 240000
\r
576 wrdprintf("m68k_wram r16: [%06x] @%06x", a, SekPc);
\r
577 if (Pico_mcd->s68k_regs[3]&4) { // 1M mode?
\r
578 int bank = Pico_mcd->s68k_regs[3]&1;
\r
579 a = (a&2) | (cell_map(a >> 2) << 2); // cell arranged
\r
580 d = *(u16 *)(Pico_mcd->word_ram1M[bank]+a);
\r
582 // allow access in any mode, like Gens does
\r
583 d = *(u16 *)(Pico_mcd->word_ram2M+(a&0x3fffe));
\r
585 wrdprintf("ret = %04x", d);
\r
587 case 0xc0>>1: case 0xc2>>1: case 0xc4>>1: case 0xc6>>1:
\r
588 case 0xc8>>1: case 0xca>>1: case 0xcc>>1: case 0xce>>1:
\r
589 case 0xd0>>1: case 0xd2>>1: case 0xd4>>1: case 0xd6>>1:
\r
590 case 0xd8>>1: case 0xda>>1: case 0xdc>>1: case 0xde>>1:
\r
592 if ((a&0xe700e0)==0xc00000)
\r
593 d=PicoVideoRead(a);
\r
595 case 0xe0>>1: case 0xe2>>1: case 0xe4>>1: case 0xe6>>1:
\r
596 case 0xe8>>1: case 0xea>>1: case 0xec>>1: case 0xee>>1:
\r
597 case 0xf0>>1: case 0xf2>>1: case 0xf4>>1: case 0xf6>>1:
\r
598 case 0xf8>>1: case 0xfa>>1: case 0xfc>>1: case 0xfe>>1:
\r
600 d=*(u16 *)(Pico.ram+(a&0xfffe));
\r
603 if ((a&0xffffc0)==0xa12000)
\r
604 rdprintf("m68k_regs r16: [%02x] @%06x", a&0x3f, SekPc);
\r
606 d = OtherRead16(a, 16);
\r
608 if ((a&0xffffc0)==0xa12000)
\r
609 rdprintf("ret = %04x", d);
\r
614 elprintf(EL_IO, "r16: %06x, %04x @%06x", a&0xffffff, d, SekPc);
\r
615 #ifdef EMU_CORE_DEBUG
\r
616 if (a>=Pico.romsize) {
\r
618 lastread_d[lrp_cyc++&15] = d;
\r
626 #ifdef _ASM_CD_MEMORY_C
\r
627 u32 PicoReadM68k32(u32 a);
\r
629 static u32 PicoReadM68k32(u32 a)
\r
637 case 0x00>>1: { // BIOS: 000000 - 020000
\r
638 u16 *pm=(u16 *)(Pico_mcd->bios+a);
\r
639 d = (pm[0]<<16)|pm[1];
\r
642 case 0x02>>1: // prg RAM
\r
643 if ((Pico_mcd->m.busreq&3)!=1) {
\r
644 u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6];
\r
645 u16 *pm=(u16 *)(prg_bank+(a&0x1fffe));
\r
646 d = (pm[0]<<16)|pm[1];
\r
649 case 0x20>>1: // word RAM: 200000 - 220000
\r
650 wrdprintf("m68k_wram r32: [%06x] @%06x", a, SekPc);
\r
652 if (Pico_mcd->s68k_regs[3]&4) { // 1M mode?
\r
653 int bank = Pico_mcd->s68k_regs[3]&1;
\r
654 u16 *pm=(u16 *)(Pico_mcd->word_ram1M[bank]+a);
\r
655 d = (pm[0]<<16)|pm[1];
\r
657 // allow access in any mode, like Gens does
\r
658 u16 *pm=(u16 *)(Pico_mcd->word_ram2M+a);
\r
659 d = (pm[0]<<16)|pm[1];
\r
661 wrdprintf("ret = %08x", d);
\r
663 case 0x22>>1: // word RAM: 220000 - 240000
\r
664 wrdprintf("m68k_wram r32: [%06x] @%06x", a, SekPc);
\r
665 if (Pico_mcd->s68k_regs[3]&4) { // 1M mode, cell arranged?
\r
667 int bank = Pico_mcd->s68k_regs[3]&1;
\r
668 a1 = (a&2) | (cell_map(a >> 2) << 2);
\r
669 if (a&2) a2 = cell_map((a+2) >> 2) << 2;
\r
671 d = *(u16 *)(Pico_mcd->word_ram1M[bank]+a1) << 16;
\r
672 d |= *(u16 *)(Pico_mcd->word_ram1M[bank]+a2);
\r
674 // allow access in any mode, like Gens does
\r
675 u16 *pm=(u16 *)(Pico_mcd->word_ram2M+(a&0x3fffe));
\r
676 d = (pm[0]<<16)|pm[1];
\r
678 wrdprintf("ret = %08x", d);
\r
680 case 0xc0>>1: case 0xc2>>1: case 0xc4>>1: case 0xc6>>1:
\r
681 case 0xc8>>1: case 0xca>>1: case 0xcc>>1: case 0xce>>1:
\r
682 case 0xd0>>1: case 0xd2>>1: case 0xd4>>1: case 0xd6>>1:
\r
683 case 0xd8>>1: case 0xda>>1: case 0xdc>>1: case 0xde>>1:
\r
685 d = (PicoVideoRead(a)<<16)|PicoVideoRead(a+2);
\r
687 case 0xe0>>1: case 0xe2>>1: case 0xe4>>1: case 0xe6>>1:
\r
688 case 0xe8>>1: case 0xea>>1: case 0xec>>1: case 0xee>>1:
\r
689 case 0xf0>>1: case 0xf2>>1: case 0xf4>>1: case 0xf6>>1:
\r
690 case 0xf8>>1: case 0xfa>>1: case 0xfc>>1: case 0xfe>>1: {
\r
692 u16 *pm=(u16 *)(Pico.ram+(a&0xfffe));
\r
693 d = (pm[0]<<16)|pm[1];
\r
697 if ((a&0xffffc0)==0xa12000)
\r
698 rdprintf("m68k_regs r32: [%02x] @%06x", a&0x3f, SekPc);
\r
700 d = (OtherRead16(a, 32)<<16)|OtherRead16(a+2, 32);
\r
702 if ((a&0xffffc0)==0xa12000)
\r
703 rdprintf("ret = %08x", d);
\r
708 elprintf(EL_IO, "r32: %06x, %08x @%06x", a&0xffffff, d, SekPc);
\r
709 #ifdef EMU_CORE_DEBUG
\r
710 if (a>=Pico.romsize) {
\r
712 lastread_d[lrp_cyc++&15] = d;
\r
720 // -----------------------------------------------------------------
\r
722 #ifdef _ASM_CD_MEMORY_C
\r
723 void PicoWriteM68k8(u32 a,u8 d);
\r
725 void PicoWriteM68k8(u32 a,u8 d)
\r
727 elprintf(EL_IO, "w8 : %06x, %02x @%06x", a&0xffffff, d, SekPc);
\r
728 #ifdef EMU_CORE_DEBUG
\r
729 lastwrite_cyc_d[lwp_cyc++&15] = d;
\r
732 if ((a&0xe00000)==0xe00000) { // Ram
\r
733 *(u8 *)(Pico.ram+((a^1)&0xffff)) = d;
\r
738 if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&3)!=1) {
\r
739 u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6];
\r
740 *(u8 *)(prg_bank+((a^1)&0x1ffff))=d;
\r
747 if ((a&0xfc0000)==0x200000) {
\r
748 wrdprintf("m68k_wram w8: [%06x] %02x @%06x", a, d, SekPc);
\r
749 if (Pico_mcd->s68k_regs[3]&4) { // 1M mode?
\r
750 int bank = Pico_mcd->s68k_regs[3]&1;
\r
752 a = (a&3) | (cell_map(a >> 2) << 2); // cell arranged
\r
754 *(u8 *)(Pico_mcd->word_ram1M[bank]+(a^1))=d;
\r
756 // allow access in any mode, like Gens does
\r
757 *(u8 *)(Pico_mcd->word_ram2M+((a^1)&0x3ffff))=d;
\r
762 if ((a&0xffffc0)==0xa12000) {
\r
763 rdprintf("m68k_regs w8: [%02x] %02x @%06x", a&0x3f, d, SekPc);
\r
764 m68k_reg_write8(a, d);
\r
773 #ifdef _ASM_CD_MEMORY_C
\r
774 void PicoWriteM68k16(u32 a,u16 d);
\r
776 static void PicoWriteM68k16(u32 a,u16 d)
\r
778 elprintf(EL_IO, "w16: %06x, %04x", a&0xffffff, d);
\r
779 #ifdef EMU_CORE_DEBUG
\r
780 lastwrite_cyc_d[lwp_cyc++&15] = d;
\r
783 if ((a&0xe00000)==0xe00000) { // Ram
\r
784 *(u16 *)(Pico.ram+(a&0xfffe))=d;
\r
789 if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&3)!=1) {
\r
790 u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6];
\r
791 wrdprintf("m68k_prgram w16: [%i,%06x] %04x @%06x", Pico_mcd->s68k_regs[3]>>6, a, d, SekPc);
\r
792 *(u16 *)(prg_bank+(a&0x1fffe))=d;
\r
799 if ((a&0xfc0000)==0x200000) {
\r
800 wrdprintf("m68k_wram w16: [%06x] %04x @%06x", a, d, SekPc);
\r
801 if (Pico_mcd->s68k_regs[3]&4) { // 1M mode?
\r
802 int bank = Pico_mcd->s68k_regs[3]&1;
\r
804 a = (a&2) | (cell_map(a >> 2) << 2); // cell arranged
\r
806 *(u16 *)(Pico_mcd->word_ram1M[bank]+a)=d;
\r
808 // allow access in any mode, like Gens does
\r
809 *(u16 *)(Pico_mcd->word_ram2M+(a&0x3fffe))=d;
\r
815 if ((a&0xffffc0)==0xa12000) {
\r
816 rdprintf("m68k_regs w16: [%02x] %04x @%06x", a&0x3f, d, SekPc);
\r
817 if (a == 0xe) { // special case, 2 byte writes would be handled differently
\r
818 Pico_mcd->s68k_regs[0xe] = d >> 8;
\r
819 #ifdef USE_POLL_DETECT
\r
820 if ((s68k_poll_adclk&0xfe) == 0xe && s68k_poll_cnt > POLL_LIMIT) {
\r
821 SekSetStopS68k(0); s68k_poll_adclk = 0;
\r
822 elprintf(EL_CDPOLL, "s68k poll release, a=%02x", a);
\r
827 m68k_reg_write8(a, d>>8);
\r
828 m68k_reg_write8(a+1,d&0xff);
\r
833 if ((a&0xe700e0)==0xc00000) {
\r
834 PicoVideoWrite(a,(u16)d);
\r
843 #ifdef _ASM_CD_MEMORY_C
\r
844 void PicoWriteM68k32(u32 a,u32 d);
\r
846 static void PicoWriteM68k32(u32 a,u32 d)
\r
848 elprintf(EL_IO, "w32: %06x, %08x", a&0xffffff, d);
\r
849 #ifdef EMU_CORE_DEBUG
\r
850 lastwrite_cyc_d[lwp_cyc++&15] = d;
\r
853 if ((a&0xe00000)==0xe00000)
\r
856 u16 *pm=(u16 *)(Pico.ram+(a&0xfffe));
\r
857 pm[0]=(u16)(d>>16); pm[1]=(u16)d;
\r
862 if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&3)!=1) {
\r
863 u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6];
\r
864 u16 *pm=(u16 *)(prg_bank+(a&0x1fffe));
\r
865 pm[0]=(u16)(d>>16); pm[1]=(u16)d;
\r
872 if ((a&0xfc0000)==0x200000) {
\r
873 if (d != 0) // don't log clears
\r
874 wrdprintf("m68k_wram w32: [%06x] %08x @%06x", a, d, SekPc);
\r
875 if (Pico_mcd->s68k_regs[3]&4) { // 1M mode?
\r
876 int bank = Pico_mcd->s68k_regs[3]&1;
\r
877 if (a >= 0x220000) { // cell arranged
\r
879 a1 = (a&2) | (cell_map(a >> 2) << 2);
\r
880 if (a&2) a2 = cell_map((a+2) >> 2) << 2;
\r
882 *(u16 *)(Pico_mcd->word_ram1M[bank]+a1) = d >> 16;
\r
883 *(u16 *)(Pico_mcd->word_ram1M[bank]+a2) = d;
\r
885 u16 *pm=(u16 *)(Pico_mcd->word_ram1M[bank]+(a&0x1fffe));
\r
886 pm[0]=(u16)(d>>16); pm[1]=(u16)d;
\r
889 // allow access in any mode, like Gens does
\r
890 u16 *pm=(u16 *)(Pico_mcd->word_ram2M+(a&0x3fffe));
\r
891 pm[0]=(u16)(d>>16); pm[1]=(u16)d;
\r
896 if ((a&0xffffc0)==0xa12000) {
\r
897 rdprintf("m68k_regs w32: [%02x] %08x @%06x", a&0x3f, d, SekPc);
\r
898 if ((a&0x3e) == 0xe) dprintf("m68k FIXME: w32 [%02x]", a&0x3f);
\r
902 if ((a&0xe700e0)==0xc00000)
\r
904 PicoVideoWrite(a, (u16)(d>>16));
\r
905 PicoVideoWrite(a+2,(u16)d);
\r
909 OtherWrite16(a, (u16)(d>>16));
\r
910 OtherWrite16(a+2,(u16)d);
\r
915 // -----------------------------------------------------------------
\r
917 // -----------------------------------------------------------------
\r
919 #ifdef _ASM_CD_MEMORY_C
\r
920 u32 PicoReadS68k8(u32 a);
\r
922 static u32 PicoReadS68k8(u32 a)
\r
926 #ifdef EMU_CORE_DEBUG
\r
933 d = *(Pico_mcd->prg_ram+(a^1));
\r
938 if ((a&0xfffe00) == 0xff8000) {
\r
940 rdprintf("s68k_regs r8: [%02x] @ %06x", a, SekPcS68k);
\r
941 if (a >= 0x0e && a < 0x30) {
\r
942 d = Pico_mcd->s68k_regs[a];
\r
943 s68k_poll_detect(a, d);
\r
944 rdprintf("ret = %02x", (u8)d);
\r
947 else if (a >= 0x58 && a < 0x68)
\r
948 d = gfx_cd_read(a&~1);
\r
949 else d = s68k_reg_read16(a&~1);
\r
950 if ((a&1)==0) d>>=8;
\r
951 rdprintf("ret = %02x", (u8)d);
\r
955 // word RAM (2M area)
\r
956 if ((a&0xfc0000)==0x080000) { // 080000-0bffff
\r
957 // test: batman returns
\r
958 wrdprintf("s68k_wram2M r8: [%06x] @%06x", a, SekPcS68k);
\r
959 if (Pico_mcd->s68k_regs[3]&4) { // 1M decode mode?
\r
960 int bank = (Pico_mcd->s68k_regs[3]&1)^1;
\r
961 d = Pico_mcd->word_ram1M[bank][((a>>1)^1)&0x1ffff];
\r
962 if (a&1) d &= 0x0f;
\r
965 // allow access in any mode, like Gens does
\r
966 d = Pico_mcd->word_ram2M[(a^1)&0x3ffff];
\r
968 wrdprintf("ret = %02x", (u8)d);
\r
972 // word RAM (1M area)
\r
973 if ((a&0xfe0000)==0x0c0000 && (Pico_mcd->s68k_regs[3]&4)) { // 0c0000-0dffff
\r
975 wrdprintf("s68k_wram1M r8: [%06x] @%06x", a, SekPcS68k);
\r
976 // if (!(Pico_mcd->s68k_regs[3]&4))
\r
977 // dprintf("s68k_wram1M FIXME: wrong mode");
\r
978 bank = (Pico_mcd->s68k_regs[3]&1)^1;
\r
979 d = Pico_mcd->word_ram1M[bank][(a^1)&0x1ffff];
\r
980 wrdprintf("ret = %02x", (u8)d);
\r
985 if ((a&0xff8000)==0xff0000) {
\r
986 elprintf(EL_IO, "s68k_pcm r8: [%06x] @%06x", a, SekPcS68k);
\r
989 d = Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][(a>>1)&0xfff];
\r
990 else if (a >= 0x20) {
\r
992 d = Pico_mcd->pcm.ch[a>>2].addr >> PCM_STEP_SHIFT;
\r
993 if (a & 2) d >>= 8;
\r
995 elprintf(EL_IO, "ret = %02x", (u8)d);
\r
1000 if ((a&0xff0000)==0xfe0000) {
\r
1001 d = Pico_mcd->bram[(a>>1)&0x1fff];
\r
1005 elprintf(EL_UIO, "s68k r8 : %06x, %02x @%06x", a&0xffffff, (u8)d, SekPcS68k);
\r
1009 elprintf(EL_IO, "s68k r8 : %06x, %02x @%06x", a&0xffffff, (u8)d, SekPcS68k);
\r
1010 #ifdef EMU_CORE_DEBUG
\r
1012 lastread_d[lrp_cyc++&15] = d;
\r
1019 #ifdef _ASM_CD_MEMORY_C
\r
1020 u32 PicoReadS68k16(u32 a);
\r
1022 static u32 PicoReadS68k16(u32 a)
\r
1026 #ifdef EMU_CORE_DEBUG
\r
1027 u32 ab=a&0xfffffe;
\r
1032 if (a < 0x80000) {
\r
1033 wrdprintf("s68k_prgram r16: [%06x] @%06x", a, SekPcS68k);
\r
1034 d = *(u16 *)(Pico_mcd->prg_ram+a);
\r
1035 wrdprintf("ret = %04x", d);
\r
1040 if ((a&0xfffe00) == 0xff8000) {
\r
1042 rdprintf("s68k_regs r16: [%02x] @ %06x", a, SekPcS68k);
\r
1043 if (a >= 0x58 && a < 0x68)
\r
1044 d = gfx_cd_read(a);
\r
1045 else d = s68k_reg_read16(a);
\r
1046 rdprintf("ret = %04x", d);
\r
1050 // word RAM (2M area)
\r
1051 if ((a&0xfc0000)==0x080000) { // 080000-0bffff
\r
1052 wrdprintf("s68k_wram2M r16: [%06x] @%06x", a, SekPcS68k);
\r
1053 if (Pico_mcd->s68k_regs[3]&4) { // 1M decode mode?
\r
1054 int bank = (Pico_mcd->s68k_regs[3]&1)^1;
\r
1055 d = Pico_mcd->word_ram1M[bank][((a>>1)^1)&0x1ffff];
\r
1056 d |= d << 4; d &= ~0xf0;
\r
1058 // allow access in any mode, like Gens does
\r
1059 d = *(u16 *)(Pico_mcd->word_ram2M+(a&0x3fffe));
\r
1061 wrdprintf("ret = %04x", d);
\r
1065 // word RAM (1M area)
\r
1066 if ((a&0xfe0000)==0x0c0000 && (Pico_mcd->s68k_regs[3]&4)) { // 0c0000-0dffff
\r
1068 wrdprintf("s68k_wram1M r16: [%06x] @%06x", a, SekPcS68k);
\r
1069 // if (!(Pico_mcd->s68k_regs[3]&4))
\r
1070 // dprintf("s68k_wram1M FIXME: wrong mode");
\r
1071 bank = (Pico_mcd->s68k_regs[3]&1)^1;
\r
1072 d = *(u16 *)(Pico_mcd->word_ram1M[bank]+(a&0x1fffe));
\r
1073 wrdprintf("ret = %04x", d);
\r
1078 if ((a&0xff0000)==0xfe0000) {
\r
1079 dprintf("FIXME: s68k_bram r16: [%06x] @%06x", a, SekPcS68k);
\r
1080 a = (a>>1)&0x1fff;
\r
1081 d = Pico_mcd->bram[a++]; // Gens does little endian here, and so do we..
\r
1082 d|= Pico_mcd->bram[a++] << 8; // This is most likely wrong
\r
1083 dprintf("ret = %04x", d);
\r
1088 if ((a&0xff8000)==0xff0000) {
\r
1089 dprintf("FIXME: s68k_pcm r16: [%06x] @%06x", a, SekPcS68k);
\r
1092 d = Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][(a>>1)&0xfff];
\r
1093 else if (a >= 0x20) {
\r
1095 d = Pico_mcd->pcm.ch[a>>2].addr >> PCM_STEP_SHIFT;
\r
1096 if (a & 2) d >>= 8;
\r
1098 dprintf("ret = %04x", d);
\r
1102 elprintf(EL_UIO, "s68k r16: %06x, %04x @%06x", a&0xffffff, d, SekPcS68k);
\r
1106 elprintf(EL_IO, "s68k r16: %06x, %04x @%06x", a&0xffffff, d, SekPcS68k);
\r
1107 #ifdef EMU_CORE_DEBUG
\r
1109 lastread_d[lrp_cyc++&15] = d;
\r
1116 #ifdef _ASM_CD_MEMORY_C
\r
1117 u32 PicoReadS68k32(u32 a);
\r
1119 static u32 PicoReadS68k32(u32 a)
\r
1123 #ifdef EMU_CORE_DEBUG
\r
1124 u32 ab=a&0xfffffe;
\r
1129 if (a < 0x80000) {
\r
1130 u16 *pm=(u16 *)(Pico_mcd->prg_ram+a);
\r
1131 d = (pm[0]<<16)|pm[1];
\r
1136 if ((a&0xfffe00) == 0xff8000) {
\r
1138 rdprintf("s68k_regs r32: [%02x] @ %06x", a, SekPcS68k);
\r
1139 if (a >= 0x58 && a < 0x68)
\r
1140 d = (gfx_cd_read(a)<<16)|gfx_cd_read(a+2);
\r
1141 else d = (s68k_reg_read16(a)<<16)|s68k_reg_read16(a+2);
\r
1142 rdprintf("ret = %08x", d);
\r
1146 // word RAM (2M area)
\r
1147 if ((a&0xfc0000)==0x080000) { // 080000-0bffff
\r
1148 wrdprintf("s68k_wram2M r32: [%06x] @%06x", a, SekPcS68k);
\r
1149 if (Pico_mcd->s68k_regs[3]&4) { // 1M decode mode?
\r
1150 int bank = (Pico_mcd->s68k_regs[3]&1)^1;
\r
1152 d = Pico_mcd->word_ram1M[bank][((a+0)^1)&0x1ffff] << 16;
\r
1153 d |= Pico_mcd->word_ram1M[bank][((a+1)^1)&0x1ffff];
\r
1154 d |= d << 4; d &= 0x0f0f0f0f;
\r
1156 // allow access in any mode, like Gens does
\r
1157 u16 *pm=(u16 *)(Pico_mcd->word_ram2M+(a&0x3fffe)); d = (pm[0]<<16)|pm[1];
\r
1159 wrdprintf("ret = %08x", d);
\r
1163 // word RAM (1M area)
\r
1164 if ((a&0xfe0000)==0x0c0000 && (Pico_mcd->s68k_regs[3]&4)) { // 0c0000-0dffff
\r
1167 wrdprintf("s68k_wram1M r32: [%06x] @%06x", a, SekPcS68k);
\r
1168 // if (!(Pico_mcd->s68k_regs[3]&4))
\r
1169 // dprintf("s68k_wram1M FIXME: wrong mode");
\r
1170 bank = (Pico_mcd->s68k_regs[3]&1)^1;
\r
1171 pm=(u16 *)(Pico_mcd->word_ram1M[bank]+(a&0x1fffe)); d = (pm[0]<<16)|pm[1];
\r
1172 wrdprintf("ret = %08x", d);
\r
1177 if ((a&0xff8000)==0xff0000) {
\r
1178 dprintf("s68k_pcm r32: [%06x] @%06x", a, SekPcS68k);
\r
1180 if (a >= 0x2000) {
\r
1182 d = Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][a&0xfff] << 16;
\r
1183 d |= Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][(a+1)&0xfff];
\r
1184 } else if (a >= 0x20) {
\r
1188 d = (Pico_mcd->pcm.ch[a].addr >> (PCM_STEP_SHIFT-8)) & 0xff0000;
\r
1189 d |= (Pico_mcd->pcm.ch[(a+1)&7].addr >> PCM_STEP_SHIFT) & 0xff;
\r
1191 d = Pico_mcd->pcm.ch[a>>2].addr >> PCM_STEP_SHIFT;
\r
1192 d = ((d<<16)&0xff0000) | ((d>>8)&0xff); // PCM chip is LE
\r
1195 dprintf("ret = %08x", d);
\r
1200 if ((a&0xff0000)==0xfe0000) {
\r
1201 dprintf("FIXME: s68k_bram r32: [%06x] @%06x", a, SekPcS68k);
\r
1202 a = (a>>1)&0x1fff;
\r
1203 d = Pico_mcd->bram[a++] << 16; // middle endian? TODO: verify against Fusion..
\r
1204 d|= Pico_mcd->bram[a++] << 24;
\r
1205 d|= Pico_mcd->bram[a++];
\r
1206 d|= Pico_mcd->bram[a++] << 8;
\r
1207 dprintf("ret = %08x", d);
\r
1211 elprintf(EL_UIO, "s68k r32: %06x, %08x @%06x", a&0xffffff, d, SekPcS68k);
\r
1215 elprintf(EL_IO, "s68k r32: %06x, %08x @%06x", a&0xffffff, d, SekPcS68k);
\r
1216 #ifdef EMU_CORE_DEBUG
\r
1217 if (ab > 0x78) { // not vectors and stuff
\r
1219 lastread_d[lrp_cyc++&15] = d;
\r
1227 #ifndef _ASM_CD_MEMORY_C
\r
1228 /* check: jaguar xj 220 (draws entire world using decode) */
\r
1229 static void decode_write8(u32 a, u8 d, int r3)
\r
1231 u8 *pd = Pico_mcd->word_ram1M[(r3 & 1)^1] + (((a>>1)^1)&0x1ffff);
\r
1232 u8 oldmask = (a&1) ? 0xf0 : 0x0f;
\r
1236 if (!(a&1)) d <<= 4;
\r
1239 if ((!(*pd & (~oldmask))) && d) goto do_it;
\r
1240 } else if (r3 > 8) {
\r
1241 if (d) goto do_it;
\r
1248 *pd = d | (*pd & oldmask);
\r
1252 static void decode_write16(u32 a, u16 d, int r3)
\r
1254 u8 *pd = Pico_mcd->word_ram1M[(r3 & 1)^1] + (((a>>1)^1)&0x1ffff);
\r
1256 //if ((a & 0x3ffff) < 0x28000) return;
\r
1264 if (!(dold & 0xf0)) dold |= d & 0xf0;
\r
1265 if (!(dold & 0x0f)) dold |= d & 0x0f;
\r
1267 } else if (r3 > 8) {
\r
1269 if (!(d & 0xf0)) d |= dold & 0xf0;
\r
1270 if (!(d & 0x0f)) d |= dold & 0x0f;
\r
1278 // -----------------------------------------------------------------
\r
1280 #ifdef _ASM_CD_MEMORY_C
\r
1281 void PicoWriteS68k8(u32 a,u8 d);
\r
1283 static void PicoWriteS68k8(u32 a,u8 d)
\r
1285 elprintf(EL_IO, "s68k w8 : %06x, %02x @%06x", a&0xffffff, d, SekPcS68k);
\r
1289 #ifdef EMU_CORE_DEBUG
\r
1290 lastwrite_cyc_d[lwp_cyc++&15] = d;
\r
1294 if (a < 0x80000) {
\r
1295 u8 *pm=(u8 *)(Pico_mcd->prg_ram+(a^1));
\r
1296 if (a >= (Pico_mcd->s68k_regs[2]<<8)) *pm=d;
\r
1301 if ((a&0xfffe00) == 0xff8000) {
\r
1303 rdprintf("s68k_regs w8: [%02x] %02x @ %06x", a, d, SekPcS68k);
\r
1304 if (a >= 0x58 && a < 0x68)
\r
1305 gfx_cd_write16(a&~1, (d<<8)|d);
\r
1306 else s68k_reg_write8(a,d);
\r
1310 // word RAM (2M area)
\r
1311 if ((a&0xfc0000)==0x080000) { // 080000-0bffff
\r
1312 int r3 = Pico_mcd->s68k_regs[3];
\r
1313 wrdprintf("s68k_wram2M w8: [%06x] %02x @%06x", a, d, SekPcS68k);
\r
1314 if (r3 & 4) { // 1M decode mode?
\r
1315 decode_write8(a, d, r3);
\r
1317 // allow access in any mode, like Gens does
\r
1318 *(u8 *)(Pico_mcd->word_ram2M+((a^1)&0x3ffff))=d;
\r
1323 // word RAM (1M area)
\r
1324 if ((a&0xfe0000)==0x0c0000 && (Pico_mcd->s68k_regs[3]&4)) { // 0c0000-0dffff
\r
1325 // Wing Commander tries to write here in wrong mode
\r
1328 wrdprintf("s68k_wram1M w8: [%06x] %02x @%06x", a, d, SekPcS68k);
\r
1329 // if (!(Pico_mcd->s68k_regs[3]&4))
\r
1330 // dprintf("s68k_wram1M FIXME: wrong mode");
\r
1331 bank = (Pico_mcd->s68k_regs[3]&1)^1;
\r
1332 *(u8 *)(Pico_mcd->word_ram1M[bank]+((a^1)&0x1ffff))=d;
\r
1337 if ((a&0xff8000)==0xff0000) {
\r
1340 Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][(a>>1)&0xfff] = d;
\r
1341 else if (a < 0x12)
\r
1342 pcm_write(a>>1, d);
\r
1347 if ((a&0xff0000)==0xfe0000) {
\r
1348 Pico_mcd->bram[(a>>1)&0x1fff] = d;
\r
1353 elprintf(EL_UIO, "s68k w8 : %06x, %02x @%06x", a&0xffffff, d, SekPcS68k);
\r
1358 #ifdef _ASM_CD_MEMORY_C
\r
1359 void PicoWriteS68k16(u32 a,u16 d);
\r
1361 static void PicoWriteS68k16(u32 a,u16 d)
\r
1363 elprintf(EL_IO, "s68k w16: %06x, %04x @%06x", a&0xffffff, d, SekPcS68k);
\r
1367 #ifdef EMU_CORE_DEBUG
\r
1368 lastwrite_cyc_d[lwp_cyc++&15] = d;
\r
1372 if (a < 0x80000) {
\r
1373 wrdprintf("s68k_prgram w16: [%06x] %04x @%06x", a, d, SekPcS68k);
\r
1374 if (a >= (Pico_mcd->s68k_regs[2]<<8)) // needed for Dungeon Explorer
\r
1375 *(u16 *)(Pico_mcd->prg_ram+a)=d;
\r
1380 if ((a&0xfffe00) == 0xff8000) {
\r
1382 rdprintf("s68k_regs w16: [%02x] %04x @ %06x", a, d, SekPcS68k);
\r
1383 if (a >= 0x58 && a < 0x68)
\r
1384 gfx_cd_write16(a, d);
\r
1386 if (a == 0xe) { // special case, 2 byte writes would be handled differently
\r
1387 Pico_mcd->s68k_regs[0xf] = d;
\r
1390 s68k_reg_write8(a, d>>8);
\r
1391 s68k_reg_write8(a+1,d&0xff);
\r
1396 // word RAM (2M area)
\r
1397 if ((a&0xfc0000)==0x080000) { // 080000-0bffff
\r
1398 int r3 = Pico_mcd->s68k_regs[3];
\r
1399 wrdprintf("s68k_wram2M w16: [%06x] %04x @%06x", a, d, SekPcS68k);
\r
1400 if (r3 & 4) { // 1M decode mode?
\r
1401 decode_write16(a, d, r3);
\r
1403 // allow access in any mode, like Gens does
\r
1404 *(u16 *)(Pico_mcd->word_ram2M+(a&0x3fffe))=d;
\r
1409 // word RAM (1M area)
\r
1410 if ((a&0xfe0000)==0x0c0000 && (Pico_mcd->s68k_regs[3]&4)) { // 0c0000-0dffff
\r
1413 wrdprintf("s68k_wram1M w16: [%06x] %04x @%06x", a, d, SekPcS68k);
\r
1414 // if (!(Pico_mcd->s68k_regs[3]&4))
\r
1415 // dprintf("s68k_wram1M FIXME: wrong mode");
\r
1416 bank = (Pico_mcd->s68k_regs[3]&1)^1;
\r
1417 *(u16 *)(Pico_mcd->word_ram1M[bank]+(a&0x1fffe))=d;
\r
1422 if ((a&0xff8000)==0xff0000) {
\r
1425 Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][(a>>1)&0xfff] = d;
\r
1426 else if (a < 0x12)
\r
1427 pcm_write(a>>1, d & 0xff);
\r
1432 if ((a&0xff0000)==0xfe0000) {
\r
1433 dprintf("s68k_bram w16: [%06x] %04x @%06x", a, d, SekPcS68k);
\r
1434 a = (a>>1)&0x1fff;
\r
1435 Pico_mcd->bram[a++] = d; // Gens does little endian here, an so do we..
\r
1436 Pico_mcd->bram[a++] = d >> 8;
\r
1441 elprintf(EL_UIO, "s68k w16: %06x, %04x @%06x", a&0xffffff, d, SekPcS68k);
\r
1446 #ifdef _ASM_CD_MEMORY_C
\r
1447 void PicoWriteS68k32(u32 a,u32 d);
\r
1449 static void PicoWriteS68k32(u32 a,u32 d)
\r
1451 elprintf(EL_IO, "s68k w32: %06x, %08x @%06x", a&0xffffff, d, SekPcS68k);
\r
1455 #ifdef EMU_CORE_DEBUG
\r
1456 lastwrite_cyc_d[lwp_cyc++&15] = d;
\r
1460 if (a < 0x80000) {
\r
1461 if (a >= (Pico_mcd->s68k_regs[2]<<8)) {
\r
1462 u16 *pm=(u16 *)(Pico_mcd->prg_ram+a);
\r
1463 pm[0]=(u16)(d>>16); pm[1]=(u16)d;
\r
1469 if ((a&0xfffe00) == 0xff8000) {
\r
1471 rdprintf("s68k_regs w32: [%02x] %08x @ %06x", a, d, SekPcS68k);
\r
1472 if (a >= 0x58 && a < 0x68) {
\r
1473 gfx_cd_write16(a, d>>16);
\r
1474 gfx_cd_write16(a+2, d&0xffff);
\r
1476 if ((a&0x1fe) == 0xe) dprintf("s68k FIXME: w32 [%02x]", a&0x3f);
\r
1477 s68k_reg_write8(a, d>>24);
\r
1478 s68k_reg_write8(a+1,(d>>16)&0xff);
\r
1479 s68k_reg_write8(a+2,(d>>8) &0xff);
\r
1480 s68k_reg_write8(a+3, d &0xff);
\r
1485 // word RAM (2M area)
\r
1486 if ((a&0xfc0000)==0x080000) { // 080000-0bffff
\r
1487 int r3 = Pico_mcd->s68k_regs[3];
\r
1488 wrdprintf("s68k_wram2M w32: [%06x] %08x @%06x", a, d, SekPcS68k);
\r
1489 if (r3 & 4) { // 1M decode mode?
\r
1490 decode_write16(a , d >> 16, r3);
\r
1491 decode_write16(a+2, d , r3);
\r
1493 // allow access in any mode, like Gens does
\r
1494 u16 *pm=(u16 *)(Pico_mcd->word_ram2M+(a&0x3fffe));
\r
1495 pm[0]=(u16)(d>>16); pm[1]=(u16)d;
\r
1500 // word RAM (1M area)
\r
1501 if ((a&0xfe0000)==0x0c0000 && (Pico_mcd->s68k_regs[3]&4)) { // 0c0000-0dffff
\r
1505 wrdprintf("s68k_wram1M w32: [%06x] %08x @%06x", a, d, SekPcS68k);
\r
1506 // if (!(Pico_mcd->s68k_regs[3]&4))
\r
1507 // dprintf("s68k_wram1M FIXME: wrong mode");
\r
1508 bank = (Pico_mcd->s68k_regs[3]&1)^1;
\r
1509 pm=(u16 *)(Pico_mcd->word_ram1M[bank]+(a&0x1fffe));
\r
1510 pm[0]=(u16)(d>>16); pm[1]=(u16)d;
\r
1515 if ((a&0xff8000)==0xff0000) {
\r
1517 if (a >= 0x2000) {
\r
1519 Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][a&0xfff] = (d >> 16);
\r
1520 Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][(a+1)&0xfff] = d;
\r
1521 } else if (a < 0x12) {
\r
1523 pcm_write(a, (d>>16) & 0xff);
\r
1524 pcm_write(a+1, d & 0xff);
\r
1530 if ((a&0xff0000)==0xfe0000) {
\r
1531 dprintf("s68k_bram w32: [%06x] %08x @%06x", a, d, SekPcS68k);
\r
1532 a = (a>>1)&0x1fff;
\r
1533 Pico_mcd->bram[a++] = d >> 16; // middle endian? verify?
\r
1534 Pico_mcd->bram[a++] = d >> 24;
\r
1535 Pico_mcd->bram[a++] = d;
\r
1536 Pico_mcd->bram[a++] = d >> 8;
\r
1541 elprintf(EL_UIO, "s68k w32: %06x, %08x @%06x", a&0xffffff, d, SekPcS68k);
\r
1546 // -----------------------------------------------------------------
\r
1550 static __inline int PicoMemBaseM68k(u32 pc)
\r
1552 if ((pc&0xe00000)==0xe00000)
\r
1553 return (int)Pico.ram-(pc&0xff0000); // Program Counter in Ram
\r
1556 return (int)Pico_mcd->bios; // Program Counter in BIOS
\r
1558 if ((pc&0xfc0000)==0x200000)
\r
1560 if (!(Pico_mcd->s68k_regs[3]&4))
\r
1561 return (int)Pico_mcd->word_ram2M - 0x200000; // Program Counter in Word Ram
\r
1562 if (pc < 0x220000) {
\r
1563 int bank = Pico_mcd->s68k_regs[3]&1;
\r
1564 return (int)Pico_mcd->word_ram1M[bank] - 0x200000;
\r
1568 // Error - Program Counter is invalid
\r
1569 elprintf(EL_ANOMALY, "m68k FIXME: unhandled jump to %06x", pc);
\r
1571 return (int)Pico_mcd->bios;
\r
1575 static u32 PicoCheckPcM68k(u32 pc)
\r
1577 pc-=PicoCpuCM68k.membase; // Get real pc
\r
1580 PicoCpuCM68k.membase=PicoMemBaseM68k(pc);
\r
1582 return PicoCpuCM68k.membase+pc;
\r
1586 static __inline int PicoMemBaseS68k(u32 pc)
\r
1588 if (pc < 0x80000) // PRG RAM
\r
1589 return (int)Pico_mcd->prg_ram;
\r
1591 if ((pc&0xfc0000)==0x080000) // WORD RAM 2M area (assume we are in the right mode..)
\r
1592 return (int)Pico_mcd->word_ram2M - 0x080000;
\r
1594 if ((pc&0xfe0000)==0x0c0000) { // word RAM 1M area
\r
1595 int bank = (Pico_mcd->s68k_regs[3]&1)^1;
\r
1596 return (int)Pico_mcd->word_ram1M[bank] - 0x0c0000;
\r
1599 // Error - Program Counter is invalid
\r
1600 elprintf(EL_ANOMALY, "s68k FIXME: unhandled jump to %06x", pc);
\r
1602 return (int)Pico_mcd->prg_ram;
\r
1606 static u32 PicoCheckPcS68k(u32 pc)
\r
1608 pc-=PicoCpuCS68k.membase; // Get real pc
\r
1611 PicoCpuCS68k.membase=PicoMemBaseS68k(pc);
\r
1613 return PicoCpuCS68k.membase+pc;
\r
1617 #ifndef _ASM_CD_MEMORY_C
\r
1618 void PicoMemResetCD(int r3)
\r
1621 // update fetchmap..
\r
1625 for (i = M68K_FETCHBANK1*2/16; (i<<(24-FAMEC_FETCHBITS)) < 0x240000; i++)
\r
1626 PicoCpuFM68k.Fetch[i] = (unsigned int)Pico_mcd->word_ram2M - 0x200000;
\r
1630 for (i = M68K_FETCHBANK1*2/16; (i<<(24-FAMEC_FETCHBITS)) < 0x220000; i++)
\r
1631 PicoCpuFM68k.Fetch[i] = (unsigned int)Pico_mcd->word_ram1M[r3 & 1] - 0x200000;
\r
1632 for (i = M68K_FETCHBANK1*0x0c/0x100; (i<<(24-FAMEC_FETCHBITS)) < 0x0e0000; i++)
\r
1633 PicoCpuFS68k.Fetch[i] = (unsigned int)Pico_mcd->word_ram1M[(r3&1)^1] - 0x0c0000;
\r
1640 static void m68k_mem_setup_cd(void);
\r
1643 PICO_INTERNAL void PicoMemSetupCD(void)
\r
1645 // additional handlers for common code
\r
1646 PicoRead16Hook = OtherRead16End;
\r
1647 PicoWrite8Hook = OtherWrite8End;
\r
1650 // Setup m68k memory callbacks:
\r
1651 PicoCpuCM68k.checkpc=PicoCheckPcM68k;
\r
1652 PicoCpuCM68k.fetch8 =PicoCpuCM68k.read8 =PicoReadM68k8;
\r
1653 PicoCpuCM68k.fetch16=PicoCpuCM68k.read16=PicoReadM68k16;
\r
1654 PicoCpuCM68k.fetch32=PicoCpuCM68k.read32=PicoReadM68k32;
\r
1655 PicoCpuCM68k.write8 =PicoWriteM68k8;
\r
1656 PicoCpuCM68k.write16=PicoWriteM68k16;
\r
1657 PicoCpuCM68k.write32=PicoWriteM68k32;
\r
1659 PicoCpuCS68k.checkpc=PicoCheckPcS68k;
\r
1660 PicoCpuCS68k.fetch8 =PicoCpuCS68k.read8 =PicoReadS68k8;
\r
1661 PicoCpuCS68k.fetch16=PicoCpuCS68k.read16=PicoReadS68k16;
\r
1662 PicoCpuCS68k.fetch32=PicoCpuCS68k.read32=PicoReadS68k32;
\r
1663 PicoCpuCS68k.write8 =PicoWriteS68k8;
\r
1664 PicoCpuCS68k.write16=PicoWriteS68k16;
\r
1665 PicoCpuCS68k.write32=PicoWriteS68k32;
\r
1669 PicoCpuFM68k.read_byte =PicoReadM68k8;
\r
1670 PicoCpuFM68k.read_word =PicoReadM68k16;
\r
1671 PicoCpuFM68k.read_long =PicoReadM68k32;
\r
1672 PicoCpuFM68k.write_byte=PicoWriteM68k8;
\r
1673 PicoCpuFM68k.write_word=PicoWriteM68k16;
\r
1674 PicoCpuFM68k.write_long=PicoWriteM68k32;
\r
1676 PicoCpuFS68k.read_byte =PicoReadS68k8;
\r
1677 PicoCpuFS68k.read_word =PicoReadS68k16;
\r
1678 PicoCpuFS68k.read_long =PicoReadS68k32;
\r
1679 PicoCpuFS68k.write_byte=PicoWriteS68k8;
\r
1680 PicoCpuFS68k.write_word=PicoWriteS68k16;
\r
1681 PicoCpuFS68k.write_long=PicoWriteS68k32;
\r
1683 // setup FAME fetchmap
\r
1687 // by default, point everything to fitst 64k of ROM (BIOS)
\r
1688 for (i = 0; i < M68K_FETCHBANK1; i++)
\r
1689 PicoCpuFM68k.Fetch[i] = (unsigned int)Pico.rom - (i<<(24-FAMEC_FETCHBITS));
\r
1690 // now real ROM (BIOS)
\r
1691 for (i = 0; i < M68K_FETCHBANK1 && (i<<(24-FAMEC_FETCHBITS)) < Pico.romsize; i++)
\r
1692 PicoCpuFM68k.Fetch[i] = (unsigned int)Pico.rom;
\r
1694 for (i = M68K_FETCHBANK1*14/16; i < M68K_FETCHBANK1; i++)
\r
1695 PicoCpuFM68k.Fetch[i] = (unsigned int)Pico.ram - (i<<(24-FAMEC_FETCHBITS));
\r
1697 // PRG RAM is default
\r
1698 for (i = 0; i < M68K_FETCHBANK1; i++)
\r
1699 PicoCpuFS68k.Fetch[i] = (unsigned int)Pico_mcd->prg_ram - (i<<(24-FAMEC_FETCHBITS));
\r
1701 for (i = 0; i < M68K_FETCHBANK1 && (i<<(24-FAMEC_FETCHBITS)) < 0x80000; i++)
\r
1702 PicoCpuFS68k.Fetch[i] = (unsigned int)Pico_mcd->prg_ram;
\r
1703 // WORD RAM 2M area
\r
1704 for (i = M68K_FETCHBANK1*0x08/0x100; i < M68K_FETCHBANK1 && (i<<(24-FAMEC_FETCHBITS)) < 0xc0000; i++)
\r
1705 PicoCpuFS68k.Fetch[i] = (unsigned int)Pico_mcd->word_ram2M - 0x80000;
\r
1706 // PicoMemResetCD() will setup word ram for both
\r
1710 m68k_mem_setup_cd();
\r
1713 // m68k_poll_addr = m68k_poll_cnt = 0;
\r
1714 s68k_poll_adclk = s68k_poll_cnt = 0;
\r
1719 static unsigned int PicoReadCD8w (unsigned int a) {
\r
1720 return m68ki_cpu_p == &PicoCpuMS68k ? PicoReadS68k8(a) : PicoReadM68k8(a);
\r
1722 static unsigned int PicoReadCD16w(unsigned int a) {
\r
1723 return m68ki_cpu_p == &PicoCpuMS68k ? PicoReadS68k16(a) : PicoReadM68k16(a);
\r
1725 static unsigned int PicoReadCD32w(unsigned int a) {
\r
1726 return m68ki_cpu_p == &PicoCpuMS68k ? PicoReadS68k32(a) : PicoReadM68k32(a);
\r
1728 static void PicoWriteCD8w (unsigned int a, unsigned char d) {
\r
1729 if (m68ki_cpu_p == &PicoCpuMS68k) PicoWriteS68k8(a, d); else PicoWriteM68k8(a, d);
\r
1731 static void PicoWriteCD16w(unsigned int a, unsigned short d) {
\r
1732 if (m68ki_cpu_p == &PicoCpuMS68k) PicoWriteS68k16(a, d); else PicoWriteM68k16(a, d);
\r
1734 static void PicoWriteCD32w(unsigned int a, unsigned int d) {
\r
1735 if (m68ki_cpu_p == &PicoCpuMS68k) PicoWriteS68k32(a, d); else PicoWriteM68k32(a, d);
\r
1738 // these are allowed to access RAM
\r
1739 static unsigned int m68k_read_pcrelative_CD8 (unsigned int a)
\r
1742 if(m68ki_cpu_p == &PicoCpuMS68k) {
\r
1743 if (a < 0x80000) return *(u8 *)(Pico_mcd->prg_ram+(a^1)); // PRG Ram
\r
1744 if ((a&0xfc0000)==0x080000 && !(Pico_mcd->s68k_regs[3]&4)) // word RAM (2M area: 080000-0bffff)
\r
1745 return *(u8 *)(Pico_mcd->word_ram2M+((a^1)&0x3ffff));
\r
1746 if ((a&0xfe0000)==0x0c0000 && (Pico_mcd->s68k_regs[3]&4)) { // word RAM (1M area: 0c0000-0dffff)
\r
1747 int bank = (Pico_mcd->s68k_regs[3]&1)^1;
\r
1748 return *(u8 *)(Pico_mcd->word_ram1M[bank]+((a^1)&0x1ffff));
\r
1750 elprintf(EL_ANOMALY, "s68k_read_pcrelative_CD8 FIXME: can't handle %06x", a);
\r
1752 if((a&0xe00000)==0xe00000) return *(u8 *)(Pico.ram+((a^1)&0xffff)); // Ram
\r
1753 if(a<0x20000) return *(u8 *)(Pico.rom+(a^1)); // Bios
\r
1754 if((a&0xfc0000)==0x200000) { // word RAM
\r
1755 if(!(Pico_mcd->s68k_regs[3]&4)) // 2M?
\r
1756 return *(u8 *)(Pico_mcd->word_ram2M+((a^1)&0x3ffff));
\r
1757 else if (a < 0x220000) {
\r
1758 int bank = Pico_mcd->s68k_regs[3]&1;
\r
1759 return *(u8 *)(Pico_mcd->word_ram1M[bank]+((a^1)&0x1ffff));
\r
1762 elprintf(EL_ANOMALY, "m68k_read_pcrelative_CD8 FIXME: can't handle %06x", a);
\r
1764 return 0;//(u8) lastread_d;
\r
1766 static unsigned int m68k_read_pcrelative_CD16(unsigned int a)
\r
1769 if(m68ki_cpu_p == &PicoCpuMS68k) {
\r
1770 if (a < 0x80000) return *(u16 *)(Pico_mcd->prg_ram+(a&~1)); // PRG Ram
\r
1771 if ((a&0xfc0000)==0x080000 && !(Pico_mcd->s68k_regs[3]&4)) // word RAM (2M area: 080000-0bffff)
\r
1772 return *(u16 *)(Pico_mcd->word_ram2M+(a&0x3fffe));
\r
1773 if ((a&0xfe0000)==0x0c0000 && (Pico_mcd->s68k_regs[3]&4)) { // word RAM (1M area: 0c0000-0dffff)
\r
1774 int bank = (Pico_mcd->s68k_regs[3]&1)^1;
\r
1775 return *(u16 *)(Pico_mcd->word_ram1M[bank]+(a&0x1fffe));
\r
1777 elprintf(EL_ANOMALY, "s68k_read_pcrelative_CD16 FIXME: can't handle %06x", a);
\r
1779 if((a&0xe00000)==0xe00000) return *(u16 *)(Pico.ram+(a&0xfffe)); // Ram
\r
1780 if(a<0x20000) return *(u16 *)(Pico.rom+(a&~1)); // Bios
\r
1781 if((a&0xfc0000)==0x200000) { // word RAM
\r
1782 if(!(Pico_mcd->s68k_regs[3]&4)) // 2M?
\r
1783 return *(u16 *)(Pico_mcd->word_ram2M+(a&0x3fffe));
\r
1784 else if (a < 0x220000) {
\r
1785 int bank = Pico_mcd->s68k_regs[3]&1;
\r
1786 return *(u16 *)(Pico_mcd->word_ram1M[bank]+(a&0x1fffe));
\r
1789 elprintf(EL_ANOMALY, "m68k_read_pcrelative_CD16 FIXME: can't handle %06x", a);
\r
1793 static unsigned int m68k_read_pcrelative_CD32(unsigned int a)
\r
1797 if(m68ki_cpu_p == &PicoCpuMS68k) {
\r
1798 if (a < 0x80000) { u16 *pm=(u16 *)(Pico_mcd->prg_ram+(a&~1)); return (pm[0]<<16)|pm[1]; } // PRG Ram
\r
1799 if ((a&0xfc0000)==0x080000 && !(Pico_mcd->s68k_regs[3]&4)) // word RAM (2M area: 080000-0bffff)
\r
1800 { pm=(u16 *)(Pico_mcd->word_ram2M+(a&0x3fffe)); return (pm[0]<<16)|pm[1]; }
\r
1801 if ((a&0xfe0000)==0x0c0000 && (Pico_mcd->s68k_regs[3]&4)) { // word RAM (1M area: 0c0000-0dffff)
\r
1802 int bank = (Pico_mcd->s68k_regs[3]&1)^1;
\r
1803 pm=(u16 *)(Pico_mcd->word_ram1M[bank]+(a&0x1fffe));
\r
1804 return (pm[0]<<16)|pm[1];
\r
1806 elprintf(EL_ANOMALY, "s68k_read_pcrelative_CD32 FIXME: can't handle %06x", a);
\r
1808 if((a&0xe00000)==0xe00000) { u16 *pm=(u16 *)(Pico.ram+(a&0xfffe)); return (pm[0]<<16)|pm[1]; } // Ram
\r
1809 if(a<0x20000) { u16 *pm=(u16 *)(Pico.rom+(a&~1)); return (pm[0]<<16)|pm[1]; }
\r
1810 if((a&0xfc0000)==0x200000) { // word RAM
\r
1811 if(!(Pico_mcd->s68k_regs[3]&4)) // 2M?
\r
1812 { pm=(u16 *)(Pico_mcd->word_ram2M+(a&0x3fffe)); return (pm[0]<<16)|pm[1]; }
\r
1813 else if (a < 0x220000) {
\r
1814 int bank = Pico_mcd->s68k_regs[3]&1;
\r
1815 pm=(u16 *)(Pico_mcd->word_ram1M[bank]+(a&0x1fffe));
\r
1816 return (pm[0]<<16)|pm[1];
\r
1819 elprintf(EL_ANOMALY, "m68k_read_pcrelative_CD32 FIXME: can't handle %06x", a);
\r
1824 extern unsigned int (*pm68k_read_memory_8) (unsigned int address);
\r
1825 extern unsigned int (*pm68k_read_memory_16)(unsigned int address);
\r
1826 extern unsigned int (*pm68k_read_memory_32)(unsigned int address);
\r
1827 extern void (*pm68k_write_memory_8) (unsigned int address, unsigned char value);
\r
1828 extern void (*pm68k_write_memory_16)(unsigned int address, unsigned short value);
\r
1829 extern void (*pm68k_write_memory_32)(unsigned int address, unsigned int value);
\r
1830 extern unsigned int (*pm68k_read_memory_pcr_8) (unsigned int address);
\r
1831 extern unsigned int (*pm68k_read_memory_pcr_16)(unsigned int address);
\r
1832 extern unsigned int (*pm68k_read_memory_pcr_32)(unsigned int address);
\r
1834 static void m68k_mem_setup_cd(void)
\r
1836 pm68k_read_memory_8 = PicoReadCD8w;
\r
1837 pm68k_read_memory_16 = PicoReadCD16w;
\r
1838 pm68k_read_memory_32 = PicoReadCD32w;
\r
1839 pm68k_write_memory_8 = PicoWriteCD8w;
\r
1840 pm68k_write_memory_16 = PicoWriteCD16w;
\r
1841 pm68k_write_memory_32 = PicoWriteCD32w;
\r
1842 pm68k_read_memory_pcr_8 = m68k_read_pcrelative_CD8;
\r
1843 pm68k_read_memory_pcr_16 = m68k_read_pcrelative_CD16;
\r
1844 pm68k_read_memory_pcr_32 = m68k_read_pcrelative_CD32;
\r
1846 #endif // EMU_M68K
\r