X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2Fcd%2FMemory.c;h=08a4486fbbc593493c2a4813db6aa9ae213b2f15;hb=c008977e8ec74b68cbccc017620a156cc39b79b2;hp=e8d0cdb6541d2bd3f1049f4ad7647089a6b76ac6;hpb=0a051f558c6585c94d06dbe670e70bcac4e0aadd;p=picodrive.git diff --git a/Pico/cd/Memory.c b/Pico/cd/Memory.c index e8d0cdb..08a4486 100644 --- a/Pico/cd/Memory.c +++ b/Pico/cd/Memory.c @@ -19,14 +19,13 @@ #include "gfx_cd.h" #include "pcm.h" -#include "cell_map.c" - typedef unsigned char u8; typedef unsigned short u16; typedef unsigned int u32; //#define __debug_io //#define __debug_io2 + //#define rdprintf dprintf #define rdprintf(...) //#define wrdprintf dprintf @@ -34,7 +33,13 @@ typedef unsigned int u32; // ----------------------------------------------------------------- +// poller detection +#define POLL_LIMIT 16 +#define POLL_CYCLES 124 +// int m68k_poll_addr, m68k_poll_cnt; +unsigned int s68k_poll_adclk, s68k_poll_cnt; +#ifndef _ASM_CD_MEMORY_C static u32 m68k_reg_read16(u32 a) { u32 d=0; @@ -47,7 +52,9 @@ static u32 m68k_reg_read16(u32 a) goto end; case 2: d = (Pico_mcd->s68k_regs[a]<<8) | (Pico_mcd->s68k_regs[a+1]&0xc7); - dprintf("m68k_regs r3: %02x @%06x", (u8)d, SekPcS68k); + // the DMNA delay must only be visible on s68k side (Lunar2, Silpheed) + if (Pico_mcd->m.state_flags&2) { d &= ~1; d |= 2; } + //printf("m68k_regs r3: %02x @%06x\n", (u8)d, SekPc); goto end; case 4: d = Pico_mcd->s68k_regs[4]<<8; @@ -62,8 +69,8 @@ static u32 m68k_reg_read16(u32 a) dprintf("m68k FIXME: reserved read"); goto end; case 0xC: - dprintf("m68k stopwatch timer read"); d = Pico_mcd->m.timer_stopwatch >> 16; + dprintf("m68k stopwatch timer read (%04x)", d); goto end; } @@ -80,8 +87,12 @@ end: // dprintf("ret = %04x", d); return d; } +#endif -static void m68k_reg_write8(u32 a, u32 d) +#ifndef _ASM_CD_MEMORY_C +static +#endif +void m68k_reg_write8(u32 a, u32 d) { a &= 0x3f; // dprintf("m68k_regs w%2i: [%02x] %02x @%06x", realsize, a, d, SekPc); @@ -98,26 +109,45 @@ static void m68k_reg_write8(u32 a, u32 d) if ( (Pico_mcd->m.busreq&2) != (d&2)) dprintf("m68k: s68k brq %i", (d&2)>>1); if ((Pico_mcd->m.state_flags&1) && (d&3)==1) { SekResetS68k(); // S68k comes out of RESET or BRQ state - Pico_mcd->m.state_flags&=~1; - dprintf("m68k: resetting s68k, cycles=%i", SekCyclesLeft); + Pico_mcd->m.state_flags&=~1; + dprintf("m68k: resetting s68k, cycles=%i", SekCyclesLeft); } Pico_mcd->m.busreq = d; return; case 2: Pico_mcd->s68k_regs[2] = d; // really use s68k side register return; - case 3: - dprintf("m68k_regs w3: %02x @%06x", (u8)d, SekPc); + case 3: { + u32 dold = Pico_mcd->s68k_regs[3]&0x1f; + //printf("m68k_regs w3: %02x @%06x\n", (u8)d, SekPc); d &= 0xc2; - if ((Pico_mcd->s68k_regs[3]>>6) != ((d>>6)&3)) + if ((dold>>6) != ((d>>6)&3)) dprintf("m68k: prg bank: %i -> %i", (Pico_mcd->s68k_regs[a]>>6), ((d>>6)&3)); //if ((Pico_mcd->s68k_regs[3]&4) != (d&4)) dprintf("m68k: ram mode %i mbit", (d&4) ? 1 : 2); //if ((Pico_mcd->s68k_regs[3]&2) != (d&2)) dprintf("m68k: %s", (d&4) ? ((d&2) ? "word swap req" : "noop?") : // ((d&2) ? "word ram to s68k" : "word ram to m68k")); - d |= Pico_mcd->s68k_regs[3]&0x1d; - if (!(d & 4) && (d & 2)) d &= ~1; // return word RAM to s68k in 2M mode - Pico_mcd->s68k_regs[3] = d; // really use s68k side register + if (dold & 4) { + d ^= 2; // writing 0 to DMNA actually sets it, 1 does nothing + } else { + //dold &= ~2; // ?? +#if 1 + if ((d & 2) && !(dold & 2)) { + Pico_mcd->m.state_flags |= 2; // we must delay setting DMNA bit (needed for Silpheed) + d &= ~2; + } +#else + if (d & 2) dold &= ~1; // return word RAM to s68k in 2M mode +#endif + } + Pico_mcd->s68k_regs[3] = d | dold; // really use s68k side register +#ifdef USE_POLL_DETECT + if ((s68k_poll_adclk&0xfe) == 2 && s68k_poll_cnt > POLL_LIMIT) { + SekSetStopS68k(0); s68k_poll_adclk = 0; + //printf("%05i:%03i: s68k poll release, a=%02x\n", Pico.m.frame_count, Pico.m.scanline, a); + } +#endif return; + } case 6: Pico_mcd->bios[0x72 + 1] = d; // simple hint vector changer return; @@ -125,14 +155,28 @@ static void m68k_reg_write8(u32 a, u32 d) Pico_mcd->bios[0x72] = d; dprintf("hint vector set to %08x", PicoRead32(0x70)); return; + case 0xf: + d = (d << 1) | ((d >> 7) & 1); // rol8 1 (special case) case 0xe: //dprintf("m68k: comm flag: %02x", d); Pico_mcd->s68k_regs[0xe] = d; +#ifdef USE_POLL_DETECT + if ((s68k_poll_adclk&0xfe) == 0xe && s68k_poll_cnt > POLL_LIMIT) { + SekSetStopS68k(0); s68k_poll_adclk = 0; + //printf("%05i:%03i: s68k poll release, a=%02x\n", Pico.m.frame_count, Pico.m.scanline, a); + } +#endif return; } if ((a&0xf0) == 0x10) { Pico_mcd->s68k_regs[a] = d; +#ifdef USE_POLL_DETECT + if ((a&0xfe) == (s68k_poll_adclk&0xfe) && s68k_poll_cnt > POLL_LIMIT) { + SekSetStopS68k(0); s68k_poll_adclk = 0; + //printf("%05i:%03i: s68k poll release, a=%02x\n", Pico.m.frame_count, Pico.m.scanline, a); + } +#endif return; } @@ -151,7 +195,10 @@ static void m68k_reg_write8(u32 a, u32 d) } -static u32 s68k_reg_read16(u32 a) +#ifndef _ASM_CD_MEMORY_C +static +#endif +u32 s68k_reg_read16(u32 a) { u32 d=0; @@ -159,77 +206,114 @@ static u32 s68k_reg_read16(u32 a) switch (a) { case 0: - d = ((Pico_mcd->s68k_regs[0]&3)<<8) | 1; // ver = 0, not in reset state - goto end; + return ((Pico_mcd->s68k_regs[0]&3)<<8) | 1; // ver = 0, not in reset state case 2: d = (Pico_mcd->s68k_regs[a]<<8) | (Pico_mcd->s68k_regs[a+1]&0x1f); - dprintf("s68k_regs r3: %02x @%06x", (u8)d, SekPc); - goto end; + //printf("s68k_regs r3: %02x @%06x\n", (u8)d, SekPcS68k); + goto poll_detect; case 6: - d = CDC_Read_Reg(); - goto end; + return CDC_Read_Reg(); case 8: - d = Read_CDC_Host(1); // Gens returns 0 here on byte reads - goto end; + return Read_CDC_Host(1); // Gens returns 0 here on byte reads case 0xC: - dprintf("s68k stopwatch timer read"); d = Pico_mcd->m.timer_stopwatch >> 16; - goto end; + dprintf("s68k stopwatch timer read (%04x)", d); + return d; case 0x30: - dprintf("s68k int3 timer read"); - break; + dprintf("s68k int3 timer read (%02x)", Pico_mcd->s68k_regs[31]); + return Pico_mcd->s68k_regs[31]; case 0x34: // fader - d = 0; // no busy bit - goto end; + return 0; // no busy bit case 0x50: // font data (check: Lunar 2, Silpheed) READ_FONT_DATA(0x00100000); - goto end; + return d; case 0x52: READ_FONT_DATA(0x00010000); - goto end; + return d; case 0x54: READ_FONT_DATA(0x10000000); - goto end; + return d; case 0x56: READ_FONT_DATA(0x01000000); - goto end; + return d; } d = (Pico_mcd->s68k_regs[a]<<8) | Pico_mcd->s68k_regs[a+1]; -end: + if (a >= 0x0e && a < 0x30) goto poll_detect; - // dprintf("ret = %04x", d); + return d; +poll_detect: +#ifdef USE_POLL_DETECT + // polling detection + if (a == (s68k_poll_adclk&0xfe)) { + unsigned int clkdiff = SekCyclesDoneS68k() - (s68k_poll_adclk>>8); + if (clkdiff <= POLL_CYCLES) { + s68k_poll_cnt++; + //printf("-- diff: %u, cnt = %i\n", clkdiff, s68k_poll_cnt); + if (s68k_poll_cnt > POLL_LIMIT) { + SekSetStopS68k(1); + //printf("%05i:%03i: s68k poll detected @ %06x, a=%02x\n", Pico.m.frame_count, Pico.m.scanline, SekPcS68k, a); + } + s68k_poll_adclk = (SekCyclesDoneS68k() << 8) | a; + return d; + } + } + s68k_poll_adclk = (SekCyclesDoneS68k() << 8) | a; + s68k_poll_cnt = 0; + +#endif return d; } -static void s68k_reg_write8(u32 a, u32 d) +#ifndef _ASM_CD_MEMORY_C +static +#endif +void s68k_reg_write8(u32 a, u32 d) { //dprintf("s68k_regs w%2i: [%02x] %02x @ %06x", realsize, a, d, SekPcS68k); // TODO: review against Gens + // Warning: d might have upper bits set switch (a) { case 2: return; // only m68k can change WP case 3: { int dold = Pico_mcd->s68k_regs[3]; - dprintf("s68k_regs w3: %02x @%06x", (u8)d, SekPc); + //printf("s68k_regs w3: %02x @%06x\n", (u8)d, SekPcS68k); d &= 0x1d; + d |= dold&0xc2; if (d&4) { - d |= dold&0xc2; - if ((d ^ dold) & 5) d &= ~2; // in case of mode or bank change we clear DMNA (m68k req) bit + if ((d ^ dold) & 5) { + d &= ~2; // in case of mode or bank change we clear DMNA (m68k req) bit +#ifdef _ASM_CD_MEMORY_C + PicoMemResetCD(d); +#endif + } +#ifdef _ASM_CD_MEMORY_C + if ((d ^ dold) & 0x1d) + PicoMemResetCDdecode(d); +#endif if (!(dold & 4)) { dprintf("wram mode 2M->1M"); wram_2M_to_1M(Pico_mcd->word_ram2M); - } + } } else { - d |= Pico_mcd->s68k_regs[3]&0xc3; - if (d&1) d &= ~2; // return word RAM to m68k in 2M mode if (dold & 4) { dprintf("wram mode 1M->2M"); + if (!(d&1)) { // it didn't set the ret bit, which means it doesn't want to give WRAM to m68k + d &= ~3; + d |= (dold&1) ? 2 : 1; // then give it to the one which had bank0 in 1M mode + } wram_1M_to_2M(Pico_mcd->word_ram2M); - } +#ifdef _ASM_CD_MEMORY_C + PicoMemResetCD(d); +#endif + } + else + d |= dold&1; + if (d&1) d &= ~2; // return word RAM to m68k in 2M mode } break; } @@ -252,12 +336,11 @@ static void s68k_reg_write8(u32 a, u32 d) Pico_mcd->m.timer_stopwatch = 0; return; case 0xe: - Pico_mcd->s68k_regs[0Xf] = (d>>1) | (d<<7); // ror8, Gens note: Dragons lair - Pico_mcd->m.timer_stopwatch = 0; + Pico_mcd->s68k_regs[0xf] = (d>>1) | (d<<7); // ror8 1, Gens note: Dragons lair return; case 0x31: dprintf("s68k set int3 timer: %02x", d); - Pico_mcd->m.timer_int3 = d << 16; + Pico_mcd->m.timer_int3 = (d & 0xff) << 16; break; case 0x33: // IRQ mask dprintf("s68k irq mask: %02x", d); @@ -294,7 +377,7 @@ static void s68k_reg_write8(u32 a, u32 d) } - +#ifndef _ASM_CD_MEMORY_C static u32 OtherRead16End(u32 a, int realsize) { u32 d=0; @@ -321,12 +404,17 @@ static void OtherWrite8End(u32 a, u32 d, int realsize) #undef _ASM_MEMORY_C #include "../MemoryCmn.c" - +#include "cell_map.c" +#endif // !def _ASM_CD_MEMORY_C // ----------------------------------------------------------------- // Read Rom and read Ram -u8 PicoReadM68k8(u32 a) +//u8 PicoReadM68k8_(u32 a); +#ifdef _ASM_CD_MEMORY_C +u8 PicoReadM68k8(u32 a); +#else +static u8 PicoReadM68k8(u32 a) { u32 d=0; @@ -337,28 +425,12 @@ u8 PicoReadM68k8(u32 a) if (a < 0x20000) { d = *(u8 *)(Pico_mcd->bios+(a^1)); goto end; } // bios // prg RAM - if ((a&0xfe0000)==0x020000) { + if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&2)) { u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6]; d = *(prg_bank+((a^1)&0x1ffff)); goto end; } -#if 0 - if (a == 0x200000 && SekPc == 0xff0b66 && Pico.m.frame_count > 1000) - { - int i; - FILE *ff; - unsigned short *ram = (unsigned short *) Pico.ram; - // unswap and dump RAM - for (i = 0; i < 0x10000/2; i++) - ram[i] = (ram[i]>>8) | (ram[i]<<8); - ff = fopen("ram.bin", "wb"); - fwrite(ram, 1, 0x10000, ff); - fclose(ff); - exit(0); - } -#endif - // word RAM if ((a&0xfc0000)==0x200000) { wrdprintf("m68k_wram r8: [%06x] @%06x", a, SekPc); @@ -393,9 +465,13 @@ u8 PicoReadM68k8(u32 a) #endif return (u8)d; } +#endif -u16 PicoReadM68k16(u32 a) +#ifdef _ASM_CD_MEMORY_C +u16 PicoReadM68k16(u32 a); +#else +static u16 PicoReadM68k16(u32 a) { u16 d=0; @@ -406,9 +482,11 @@ u16 PicoReadM68k16(u32 a) if (a < 0x20000) { d = *(u16 *)(Pico_mcd->bios+a); goto end; } // bios // prg RAM - if ((a&0xfe0000)==0x020000) { + if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&2)) { u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6]; + wrdprintf("m68k_prgram r16: [%i,%06x] @%06x", Pico_mcd->s68k_regs[3]>>6, a, SekPc); d = *(u16 *)(prg_bank+(a&0x1fffe)); + wrdprintf("ret = %04x", d); goto end; } @@ -421,7 +499,6 @@ u16 PicoReadM68k16(u32 a) a = (a&2) | (cell_map(a >> 2) << 2); // cell arranged else a &= 0x1fffe; d = *(u16 *)(Pico_mcd->word_ram1M[bank]+a); -//d = 0xaaaa; } else { // allow access in any mode, like Gens does d = *(u16 *)(Pico_mcd->word_ram2M+(a&0x3fffe)); @@ -445,9 +522,13 @@ u16 PicoReadM68k16(u32 a) #endif return d; } +#endif -u32 PicoReadM68k32(u32 a) +#ifdef _ASM_CD_MEMORY_C +u32 PicoReadM68k32(u32 a); +#else +static u32 PicoReadM68k32(u32 a) { u32 d=0; @@ -458,7 +539,7 @@ u32 PicoReadM68k32(u32 a) if (a < 0x20000) { u16 *pm=(u16 *)(Pico_mcd->bios+a); d = (pm[0]<<16)|pm[1]; goto end; } // bios // prg RAM - if ((a&0xfe0000)==0x020000) { + if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&2)) { u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6]; u16 *pm=(u16 *)(prg_bank+(a&0x1fffe)); d = (pm[0]<<16)|pm[1]; @@ -473,10 +554,10 @@ u32 PicoReadM68k32(u32 a) if (a >= 0x220000) { // cell arranged u32 a1, a2; a1 = (a&2) | (cell_map(a >> 2) << 2); - if (a&2) a2 = cell_map((a+2) >> 2) << 2; - else a2 = a1 + 2; - d = *(u16 *)(Pico_mcd->word_ram1M[bank]+a1) << 16; - d |= *(u16 *)(Pico_mcd->word_ram1M[bank]+a2); + if (a&2) a2 = cell_map((a+2) >> 2) << 2; + else a2 = a1 + 2; + d = *(u16 *)(Pico_mcd->word_ram1M[bank]+a1) << 16; + d |= *(u16 *)(Pico_mcd->word_ram1M[bank]+a2); } else { u16 *pm=(u16 *)(Pico_mcd->word_ram1M[bank]+(a&0x1fffe)); d = (pm[0]<<16)|pm[1]; } @@ -502,12 +583,16 @@ u32 PicoReadM68k32(u32 a) #endif return d; } +#endif // ----------------------------------------------------------------- // Write Ram -void PicoWriteM68k8(u32 a,u8 d) +#ifdef _ASM_CD_MEMORY_C +void PicoWriteM68k8(u32 a,u8 d); +#else +static void PicoWriteM68k8(u32 a,u8 d) { #ifdef __debug_io dprintf("w8 : %06x, %02x @%06x", a&0xffffff, d, SekPc); @@ -524,7 +609,7 @@ void PicoWriteM68k8(u32 a,u8 d) a&=0xffffff; // prg RAM - if ((a&0xfe0000)==0x020000) { + if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&2)) { u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6]; *(u8 *)(prg_bank+((a^1)&0x1ffff))=d; return; @@ -551,9 +636,13 @@ void PicoWriteM68k8(u32 a,u8 d) OtherWrite8(a,d,8); } +#endif -void PicoWriteM68k16(u32 a,u16 d) +#ifdef _ASM_CD_MEMORY_C +void PicoWriteM68k16(u32 a,u16 d); +#else +static void PicoWriteM68k16(u32 a,u16 d) { #ifdef __debug_io dprintf("w16: %06x, %04x", a&0xffffff, d); @@ -568,8 +657,9 @@ void PicoWriteM68k16(u32 a,u16 d) a&=0xfffffe; // prg RAM - if ((a&0xfe0000)==0x020000) { + if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&2)) { u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6]; + wrdprintf("m68k_prgram w16: [%i,%06x] %04x @%06x", Pico_mcd->s68k_regs[3]>>6, a, d, SekPc); *(u16 *)(prg_bank+(a&0x1fffe))=d; return; } @@ -590,14 +680,33 @@ void PicoWriteM68k16(u32 a,u16 d) return; } - if ((a&0xffffc0)==0xa12000) + // regs + if ((a&0xffffc0)==0xa12000) { rdprintf("m68k_regs w16: [%02x] %04x @%06x", a&0x3f, d, SekPc); + if (a == 0xe) { // special case, 2 byte writes would be handled differently + Pico_mcd->s68k_regs[0xe] = d >> 8; +#ifdef USE_POLL_DETECT + if ((s68k_poll_adclk&0xfe) == 0xe && s68k_poll_cnt > POLL_LIMIT) { + SekSetStopS68k(0); s68k_poll_adclk = -1; + //printf("%05i:%03i: s68k poll release, a=%02x\n", Pico.m.frame_count, Pico.m.scanline, a); + } +#endif + return; + } + m68k_reg_write8(a, d>>8); + m68k_reg_write8(a+1,d&0xff); + return; + } OtherWrite16(a,d); } +#endif -void PicoWriteM68k32(u32 a,u32 d) +#ifdef _ASM_CD_MEMORY_C +void PicoWriteM68k32(u32 a,u32 d); +#else +static void PicoWriteM68k32(u32 a,u32 d) { #ifdef __debug_io dprintf("w32: %06x, %08x", a&0xffffff, d); @@ -614,7 +723,7 @@ void PicoWriteM68k32(u32 a,u32 d) a&=0xfffffe; // prg RAM - if ((a&0xfe0000)==0x020000) { + if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&2)) { u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6]; u16 *pm=(u16 *)(prg_bank+(a&0x1fffe)); pm[0]=(u16)(d>>16); pm[1]=(u16)d; @@ -630,10 +739,10 @@ void PicoWriteM68k32(u32 a,u32 d) if (a >= 0x220000) { // cell arranged u32 a1, a2; a1 = (a&2) | (cell_map(a >> 2) << 2); - if (a&2) a2 = cell_map((a+2) >> 2) << 2; - else a2 = a1 + 2; - *(u16 *)(Pico_mcd->word_ram1M[bank]+a1) = d >> 16; - *(u16 *)(Pico_mcd->word_ram1M[bank]+a2) = d; + if (a&2) a2 = cell_map((a+2) >> 2) << 2; + else a2 = a1 + 2; + *(u16 *)(Pico_mcd->word_ram1M[bank]+a1) = d >> 16; + *(u16 *)(Pico_mcd->word_ram1M[bank]+a2) = d; } else { u16 *pm=(u16 *)(Pico_mcd->word_ram1M[bank]+(a&0x1fffe)); pm[0]=(u16)(d>>16); pm[1]=(u16)d; @@ -652,12 +761,15 @@ void PicoWriteM68k32(u32 a,u32 d) OtherWrite16(a, (u16)(d>>16)); OtherWrite16(a+2,(u16)d); } +#endif // ----------------------------------------------------------------- - -u8 PicoReadS68k8(u32 a) +#ifdef _ASM_CD_MEMORY_C +u8 PicoReadS68k8(u32 a); +#else +static u8 PicoReadS68k8(u32 a) { u32 d=0; @@ -741,9 +853,14 @@ u8 PicoReadS68k8(u32 a) #endif return (u8)d; } +#endif -u16 PicoReadS68k16(u32 a) +//u16 PicoReadS68k16_(u32 a); +#ifdef _ASM_CD_MEMORY_C +u16 PicoReadS68k16(u32 a); +#else +static u16 PicoReadS68k16(u32 a) { u32 d=0; @@ -751,7 +868,9 @@ u16 PicoReadS68k16(u32 a) // prg RAM if (a < 0x80000) { + wrdprintf("s68k_prgram r16: [%06x] @%06x", a, SekPcS68k); d = *(u16 *)(Pico_mcd->prg_ram+a); + wrdprintf("ret = %04x", d); goto end; } @@ -796,17 +915,17 @@ u16 PicoReadS68k16(u32 a) // bram if ((a&0xff0000)==0xfe0000) { - dprintf("s68k_bram r16: [%06x] @%06x", a, SekPcS68k); + dprintf("FIXME: s68k_bram r16: [%06x] @%06x", a, SekPcS68k); a = (a>>1)&0x1fff; d = Pico_mcd->bram[a++]; // Gens does little endian here, and so do we.. - d|= Pico_mcd->bram[a++] << 8; + d|= Pico_mcd->bram[a++] << 8; // This is most likely wrong dprintf("ret = %04x", d); goto end; } // PCM if ((a&0xff8000)==0xff0000) { - dprintf("s68k_pcm r16: [%06x] @%06x", a, SekPcS68k); + dprintf("FIXME: s68k_pcm r16: [%06x] @%06x", a, SekPcS68k); a &= 0x7fff; if (a >= 0x2000) d = Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][(a>>1)&0xfff]; @@ -828,9 +947,13 @@ u16 PicoReadS68k16(u32 a) #endif return d; } +#endif -u32 PicoReadS68k32(u32 a) +#ifdef _ASM_CD_MEMORY_C +u32 PicoReadS68k32(u32 a); +#else +static u32 PicoReadS68k32(u32 a) { u32 d=0; @@ -863,7 +986,6 @@ u32 PicoReadS68k32(u32 a) d = Pico_mcd->word_ram1M[bank][((a+0)^1)&0x1ffff] << 16; d |= Pico_mcd->word_ram1M[bank][((a+1)^1)&0x1ffff]; d |= d << 4; d &= 0x0f0f0f0f; - dprintf("FIXME: decode"); } else { // allow access in any mode, like Gens does u16 *pm=(u16 *)(Pico_mcd->word_ram2M+(a&0x3fffe)); d = (pm[0]<<16)|pm[1]; @@ -886,7 +1008,7 @@ u32 PicoReadS68k32(u32 a) // PCM if ((a&0xff8000)==0xff0000) { - dprintf("s68k_pcm r32: [%06x] @%06x", a, SekPcS68k); + dprintf("FIXME: s68k_pcm r32: [%06x] @%06x", a, SekPcS68k); a &= 0x7fff; if (a >= 0x2000) { a >>= 1; @@ -909,7 +1031,7 @@ u32 PicoReadS68k32(u32 a) // bram if ((a&0xff0000)==0xfe0000) { - dprintf("s68k_bram r32: [%06x] @%06x", a, SekPcS68k); + dprintf("FIXME: s68k_bram r32: [%06x] @%06x", a, SekPcS68k); a = (a>>1)&0x1fff; d = Pico_mcd->bram[a++] << 16; // middle endian? TODO: verify against Fusion.. d|= Pico_mcd->bram[a++] << 24; @@ -928,23 +1050,20 @@ u32 PicoReadS68k32(u32 a) #endif return d; } +#endif +#ifndef _ASM_CD_MEMORY_C /* check: jaguar xj 220 (draws entire world using decode) */ static void decode_write8(u32 a, u8 d, int r3) { u8 *pd = Pico_mcd->word_ram1M[!(r3 & 1)] + (((a>>1)^1)&0x1ffff); u8 oldmask = (a&1) ? 0xf0 : 0x0f; - //if ((a & 0x3ffff) < 0x28000) return; - //return; - r3 &= 0x18; d &= 0x0f; if (!(a&1)) d <<= 4; - //dprintf("FIXME: decode, r3 = %02x", r3); - if (r3 == 8) { if ((!(*pd & (~oldmask))) && d) goto do_it; } else if (r3 > 8) { @@ -982,14 +1101,15 @@ static void decode_write16(u32 a, u16 d, int r3) } else { *pd = d; } - - //dprintf("FIXME: decode"); } - +#endif // ----------------------------------------------------------------- -void PicoWriteS68k8(u32 a,u8 d) +#ifdef _ASM_CD_MEMORY_C +void PicoWriteS68k8(u32 a,u8 d); +#else +static void PicoWriteS68k8(u32 a,u8 d) { #ifdef __debug_io2 dprintf("s68k w8 : %06x, %02x @%06x", a&0xffffff, d, SekPcS68k); @@ -1009,7 +1129,7 @@ void PicoWriteS68k8(u32 a,u8 d) a &= 0x1ff; rdprintf("s68k_regs w8: [%02x] %02x @ %06x", a, d, SekPcS68k); if (a >= 0x58 && a < 0x68) - gfx_cd_write(a&~1, (d<<8)|d); + gfx_cd_write16(a&~1, (d<<8)|d); else s68k_reg_write8(a,d); return; } @@ -1059,9 +1179,13 @@ void PicoWriteS68k8(u32 a,u8 d) dprintf("s68k w8 : %06x, %02x @%06x", a&0xffffff, d, SekPcS68k); } +#endif -void PicoWriteS68k16(u32 a,u16 d) +#ifdef _ASM_CD_MEMORY_C +void PicoWriteS68k16(u32 a,u16 d); +#else +static void PicoWriteS68k16(u32 a,u16 d) { #ifdef __debug_io2 dprintf("s68k w16: %06x, %04x @%06x", a&0xffffff, d, SekPcS68k); @@ -1071,6 +1195,7 @@ void PicoWriteS68k16(u32 a,u16 d) // prg RAM if (a < 0x80000) { + wrdprintf("s68k_prgram w16: [%06x] %04x @%06x", a, d, SekPcS68k); *(u16 *)(Pico_mcd->prg_ram+a)=d; return; } @@ -1080,11 +1205,11 @@ void PicoWriteS68k16(u32 a,u16 d) a &= 0x1fe; rdprintf("s68k_regs w16: [%02x] %04x @ %06x", a, d, SekPcS68k); if (a >= 0x58 && a < 0x68) - gfx_cd_write(a, d); + gfx_cd_write16(a, d); else { if (a == 0xe) { // special case, 2 byte writes would be handled differently Pico_mcd->s68k_regs[0xf] = d; - return; + return; } s68k_reg_write8(a, d>>8); s68k_reg_write8(a+1,d&0xff); @@ -1139,9 +1264,13 @@ void PicoWriteS68k16(u32 a,u16 d) dprintf("s68k w16: %06x, %04x @%06x", a&0xffffff, d, SekPcS68k); } +#endif -void PicoWriteS68k32(u32 a,u32 d) +#ifdef _ASM_CD_MEMORY_C +void PicoWriteS68k32(u32 a,u32 d); +#else +static void PicoWriteS68k32(u32 a,u32 d) { #ifdef __debug_io2 dprintf("s68k w32: %06x, %08x @%06x", a&0xffffff, d, SekPcS68k); @@ -1161,8 +1290,8 @@ void PicoWriteS68k32(u32 a,u32 d) a &= 0x1fe; rdprintf("s68k_regs w32: [%02x] %08x @ %06x", a, d, SekPcS68k); if (a >= 0x58 && a < 0x68) { - gfx_cd_write(a, d>>16); - gfx_cd_write(a+2, d&0xffff); + gfx_cd_write16(a, d>>16); + gfx_cd_write16(a+2, d&0xffff); } else { s68k_reg_write8(a, d>>24); s68k_reg_write8(a+1,(d>>16)&0xff); @@ -1230,7 +1359,7 @@ void PicoWriteS68k32(u32 a,u32 d) dprintf("s68k w32: %06x, %08x @%06x", a&0xffffff, d, SekPcS68k); } - +#endif // ----------------------------------------------------------------- @@ -1326,6 +1455,8 @@ void PicoMemSetupCD() PicoCpuS68k.write16=PicoWriteS68k16; PicoCpuS68k.write32=PicoWriteS68k32; #endif + // m68k_poll_addr = m68k_poll_cnt = 0; + s68k_poll_adclk = s68k_poll_cnt = 0; }