X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2Fcd%2FMemory.c;h=a6267fed6326c4677a95b28abf11ab7807adeb74;hb=7969166ef66a8623cb4d8c609eb6e67314aefd79;hp=fc6e4de54c48bfe725ba7d4d27cc9c176632cac0;hpb=2433f409129279095926eb00cf8ab429738f80dd;p=picodrive.git diff --git a/Pico/cd/Memory.c b/Pico/cd/Memory.c index fc6e4de..a6267fe 100644 --- a/Pico/cd/Memory.c +++ b/Pico/cd/Memory.c @@ -1,10 +1,6 @@ -// This is part of Pico Library - -// (c) Copyright 2004 Dave, All rights reserved. -// (c) Copyright 2007 notaz, All rights reserved. -// Free for non-commercial use. - -// For commercial use, separate licencing terms must be obtained. +// Memory I/O handlers for Sega/Mega CD. +// Loosely based on Gens code. +// (c) Copyright 2007, Grazvydas "notaz" Ignotas // A68K no longer supported here @@ -12,26 +8,28 @@ #include "../PicoInt.h" -#include "../sound/sound.h" #include "../sound/ym2612.h" #include "../sound/sn76496.h" #include "gfx_cd.h" #include "pcm.h" +#ifndef UTYPES_DEFINED typedef unsigned char u8; typedef unsigned short u16; typedef unsigned int u32; +#define UTYPES_DEFINED +#endif //#define __debug_io //#define __debug_io2 -//#define rdprintf dprintf -#define rdprintf(...) +#define rdprintf dprintf +//#define rdprintf(...) //#define wrdprintf dprintf #define wrdprintf(...) -//#define plprintf dprintf -#define plprintf(...) +#define plprintf dprintf +//#define plprintf(...) // ----------------------------------------------------------------- @@ -118,6 +116,7 @@ void m68k_reg_write8(u32 a, u32 d) Pico_mcd->m.busreq = d; return; case 2: + dprintf("m68k: prg wp=%02x", d); Pico_mcd->s68k_regs[2] = d; // really use s68k side register return; case 3: { @@ -405,7 +404,7 @@ static void OtherWrite8End(u32 a, u32 d, int realsize) { if ((a&0xffffc0)==0xa12000) { m68k_reg_write8(a, d); return; } - dprintf("m68k FIXME: strange w%i: %06x, %08x @%06x", realsize, a&0xffffff, d, SekPc); + dprintf("m68k FIXME: strange w%i: [%06x], %08x @%06x", realsize, a&0xffffff, d, SekPc); } @@ -420,9 +419,9 @@ static void OtherWrite8End(u32 a, u32 d, int realsize) //u8 PicoReadM68k8_(u32 a); #ifdef _ASM_CD_MEMORY_C -u8 PicoReadM68k8(u32 a); +u32 PicoReadM68k8(u32 a); #else -static u8 PicoReadM68k8(u32 a) +static u32 PicoReadM68k8(u32 a) { u32 d=0; @@ -433,7 +432,7 @@ static u8 PicoReadM68k8(u32 a) if (a < 0x20000) { d = *(u8 *)(Pico_mcd->bios+(a^1)); goto end; } // bios // prg RAM - if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&2)) { + if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&3)!=1) { u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6]; d = *(prg_bank+((a^1)&0x1ffff)); goto end; @@ -471,17 +470,17 @@ static u8 PicoReadM68k8(u32 a) #ifdef __debug_io dprintf("r8 : %06x, %02x @%06x", a&0xffffff, (u8)d, SekPc); #endif - return (u8)d; + return d; } #endif #ifdef _ASM_CD_MEMORY_C -u16 PicoReadM68k16(u32 a); +u32 PicoReadM68k16(u32 a); #else -static u16 PicoReadM68k16(u32 a) +static u32 PicoReadM68k16(u32 a) { - u16 d=0; + u32 d=0; if ((a&0xe00000)==0xe00000) { d=*(u16 *)(Pico.ram+(a&0xfffe)); goto end; } // Ram @@ -490,7 +489,7 @@ static u16 PicoReadM68k16(u32 a) if (a < 0x20000) { d = *(u16 *)(Pico_mcd->bios+a); goto end; } // bios // prg RAM - if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&2)) { + if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&3)!=1) { 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)); @@ -518,7 +517,7 @@ static u16 PicoReadM68k16(u32 a) if ((a&0xffffc0)==0xa12000) rdprintf("m68k_regs r16: [%02x] @%06x", a&0x3f, SekPc); - d = (u16)OtherRead16(a, 16); + d = OtherRead16(a, 16); if ((a&0xffffc0)==0xa12000) rdprintf("ret = %04x", d); @@ -547,7 +546,7 @@ static 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 && (Pico_mcd->m.busreq&2)) { + if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&3)!=1) { 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]; @@ -595,7 +594,6 @@ static u32 PicoReadM68k32(u32 a) // ----------------------------------------------------------------- -// Write Ram #ifdef _ASM_CD_MEMORY_C void PicoWriteM68k8(u32 a,u8 d); @@ -617,7 +615,7 @@ static void PicoWriteM68k8(u32 a,u8 d) a&=0xffffff; // prg RAM - if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&2)) { + if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&3)!=1) { u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6]; *(u8 *)(prg_bank+((a^1)&0x1ffff))=d; return; @@ -645,7 +643,7 @@ static void PicoWriteM68k8(u32 a,u8 d) return; } - OtherWrite8(a,d,8); + OtherWrite8(a,d); } #endif @@ -668,7 +666,7 @@ static void PicoWriteM68k16(u32 a,u16 d) a&=0xfffffe; // prg RAM - if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&2)) { + if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&3)!=1) { 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; @@ -698,7 +696,7 @@ static void PicoWriteM68k16(u32 a,u16 d) 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; + SekSetStopS68k(0); s68k_poll_adclk = 0; plprintf("s68k poll release, a=%02x\n", a); } #endif @@ -734,7 +732,7 @@ static void PicoWriteM68k32(u32 a,u32 d) a&=0xfffffe; // prg RAM - if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&2)) { + if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&3)!=1) { 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; @@ -777,12 +775,14 @@ static void PicoWriteM68k32(u32 a,u32 d) #endif +// ----------------------------------------------------------------- +// S68k // ----------------------------------------------------------------- #ifdef _ASM_CD_MEMORY_C -u8 PicoReadS68k8(u32 a); +u32 PicoReadS68k8(u32 a); #else -static u8 PicoReadS68k8(u32 a) +static u32 PicoReadS68k8(u32 a) { u32 d=0; @@ -870,16 +870,15 @@ static u8 PicoReadS68k8(u32 a) #ifdef __debug_io2 dprintf("s68k r8 : %06x, %02x @%06x", a&0xffffff, (u8)d, SekPcS68k); #endif - return (u8)d; + return d; } #endif -//u16 PicoReadS68k16_(u32 a); #ifdef _ASM_CD_MEMORY_C -u16 PicoReadS68k16(u32 a); +u32 PicoReadS68k16(u32 a); #else -static u16 PicoReadS68k16(u32 a) +static u32 PicoReadS68k16(u32 a) { u32 d=0; @@ -1139,7 +1138,7 @@ static void PicoWriteS68k8(u32 a,u8 d) // prg RAM if (a < 0x80000) { u8 *pm=(u8 *)(Pico_mcd->prg_ram+(a^1)); - *pm=d; + if (a >= (Pico_mcd->s68k_regs[2]<<8)) *pm=d; return; } @@ -1215,7 +1214,8 @@ static 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; + if (a >= (Pico_mcd->s68k_regs[2]<<8)) // needed for Dungeon Explorer + *(u16 *)(Pico_mcd->prg_ram+a)=d; return; } @@ -1299,8 +1299,10 @@ static void PicoWriteS68k32(u32 a,u32 d) // prg RAM if (a < 0x80000) { - u16 *pm=(u16 *)(Pico_mcd->prg_ram+a); - pm[0]=(u16)(d>>16); pm[1]=(u16)d; + if (a >= (Pico_mcd->s68k_regs[2]<<8)) { + u16 *pm=(u16 *)(Pico_mcd->prg_ram+a); + pm[0]=(u16)(d>>16); pm[1]=(u16)d; + } return; } @@ -1454,7 +1456,7 @@ static u32 PicoCheckPcS68k(u32 pc) #endif -void PicoMemSetupCD() +PICO_INTERNAL void PicoMemSetupCD(void) { dprintf("PicoMemSetupCD()"); #ifdef EMU_C68K