#if PICODRIVE_HACKS\r
static inline unsigned char picodrive_read(unsigned short a)\r
{\r
- return (a < 0x4000) ? Pico.zram[a&0x1fff] : z80_read(a);\r
+ unsigned long v = z80_read_map[a >> Z80_MEM_SHIFT];\r
+ if (v & 0x80000000)\r
+ return ((z80_read_f *)(v << 1))(a);\r
+ return *(unsigned char *)((v << 1) + a);\r
}\r
#endif\r
\r
#define WRITE_MEM8(A, D) { \\r
unsigned short a = A; \\r
unsigned char d = D; \\r
- if (a < 0x4000) Pico.zram[a&0x1fff] = d; \\r
- else z80_write(a, d); \\r
+ unsigned long v = z80_write_map[a >> Z80_MEM_SHIFT]; \\r
+ if (v & 0x80000000) \\r
+ ((z80_write_f *)(v << 1))(a, d); \\r
+ else \\r
+ *(unsigned char *)((v << 1) + a) = d; \\r
}\r
#else\r
#define WRITE_MEM8(A, D) CPU->Write_Byte(A, D);\r
#define UTYPES_DEFINED\r
#endif\r
\r
-extern unsigned int lastSSRamWrite; // used by serial SRAM code\r
+extern unsigned int lastSSRamWrite; // used by serial eeprom code\r
\r
#ifdef _ASM_MEMORY_C\r
u32 PicoRead8(u32 a);\r
PicoWrite16Hook = OtherWrite16End;\r
}\r
\r
+static void z80_mem_setup(void);\r
#ifdef EMU_M68K\r
static void m68k_mem_setup(void);\r
#endif\r
#ifdef EMU_M68K\r
m68k_mem_setup();\r
#endif\r
+\r
+ z80_mem_setup();\r
}\r
\r
/* some nasty things below :( */\r
if (xcycles >= timer_b_next_oflow) \\r
ym2612.OPN.ST.status |= (ym2612.OPN.ST.mode >> 2) & 2\r
\r
-u32 ym2612_read_local_z80(void)\r
+static u32 MEMH_FUNC ym2612_read_local_z80(void)\r
{\r
int xcycles = z80_cyclesDone() << 8;\r
\r
// -----------------------------------------------------------------\r
// z80 memhandlers\r
\r
-PICO_INTERNAL unsigned char z80_read(unsigned short a)\r
+static unsigned char MEMH_FUNC z80_md_vdp_read(unsigned short a)\r
{\r
- u8 ret = 0;\r
+ // TODO?\r
+ elprintf(EL_ANOMALY, "z80 invalid r8 [%06x] %02x", a, 0xff);\r
+ return 0xff;\r
+}\r
\r
- if ((a>>13)==2) // 0x4000-0x5fff (Charles MacDonald)\r
- {\r
- return ym2612_read_local_z80();\r
- }\r
+static unsigned char MEMH_FUNC z80_md_bank_read(unsigned short a)\r
+{\r
+ extern unsigned int PicoReadM68k8(unsigned int a);\r
+ unsigned int addr68k;\r
+ unsigned char ret;\r
\r
- if (a>=0x8000)\r
- {\r
- extern u32 PicoReadM68k8(u32 a);\r
- u32 addr68k;\r
- addr68k=Pico.m.z80_bank68k<<15;\r
- addr68k+=a&0x7fff;\r
-\r
- if (addr68k < Pico.romsize) { ret = Pico.rom[addr68k^1]; goto bnkend; }\r
- elprintf(EL_ANOMALY, "z80->68k upper read [%06x] %02x", addr68k, ret);\r
- if (PicoAHW & PAHW_MCD)\r
- ret = PicoReadM68k8(addr68k);\r
- else ret = PicoRead8(addr68k);\r
-bnkend:\r
- elprintf(EL_Z80BNK, "z80->68k r8 [%06x] %02x", addr68k, ret);\r
- return ret;\r
+ addr68k = Pico.m.z80_bank68k<<15;\r
+ addr68k += a & 0x7fff;\r
+\r
+ if (addr68k < Pico.romsize) {\r
+ ret = Pico.rom[addr68k^1];\r
+ goto out;\r
}\r
\r
- // should not be needed, cores should be able to access RAM themselves\r
- if (a<0x4000) return Pico.zram[a&0x1fff];\r
+ elprintf(EL_ANOMALY, "z80->68k upper read [%06x] %02x", addr68k, ret);\r
+ if (PicoAHW & PAHW_MCD)\r
+ ret = PicoReadM68k8(addr68k);\r
+ else ret = PicoRead8(addr68k);\r
\r
- elprintf(EL_ANOMALY, "z80 invalid r8 [%06x] %02x", a, ret);\r
+out:\r
+ elprintf(EL_Z80BNK, "z80->68k r8 [%06x] %02x", addr68k, ret);\r
return ret;\r
}\r
\r
-#ifndef _USE_CZ80\r
-PICO_INTERNAL_ASM void z80_write(unsigned char data, unsigned short a)\r
-#else\r
-PICO_INTERNAL_ASM void z80_write(unsigned int a, unsigned char data)\r
-#endif\r
+static void MEMH_FUNC z80_md_ym2612_write(unsigned int a, unsigned char data)\r
{\r
- if ((a>>13)==2) // 0x4000-0x5fff (Charles MacDonald)\r
- {\r
- if(PicoOpt&POPT_EN_FM) emustatus|=ym2612_write_local(a, data, 1) & 1;\r
- return;\r
- }\r
+ if (PicoOpt & POPT_EN_FM)\r
+ emustatus |= ym2612_write_local(a, data, 1) & 1;\r
+}\r
\r
- if ((a&0xfff9)==0x7f11) // 7f11 7f13 7f15 7f17\r
+static void MEMH_FUNC z80_md_vdp_br_write(unsigned int a, unsigned char data)\r
+{\r
+ // TODO: allow full VDP access\r
+ if ((a&0xfff9) == 0x7f11) // 7f11 7f13 7f15 7f17\r
{\r
- if(PicoOpt&POPT_EN_PSG) SN76496Write(data);\r
+ if (PicoOpt & POPT_EN_PSG)\r
+ SN76496Write(data);\r
return;\r
}\r
\r
- if ((a>>8)==0x60)\r
+ if ((a>>8) == 0x60)\r
{\r
- Pico.m.z80_bank68k>>=1;\r
- Pico.m.z80_bank68k|=(data&1)<<8;\r
- Pico.m.z80_bank68k&=0x1ff; // 9 bits and filled in the new top one\r
+ Pico.m.z80_bank68k >>= 1;\r
+ Pico.m.z80_bank68k |= data << 8;\r
+ Pico.m.z80_bank68k &= 0x1ff; // 9 bits and filled in the new top one\r
return;\r
}\r
\r
- if (a>=0x8000)\r
- {\r
- extern void PicoWriteM68k8(u32 a,u8 d);\r
- u32 addr68k;\r
- addr68k=Pico.m.z80_bank68k<<15;\r
- addr68k+=a&0x7fff;\r
- elprintf(EL_Z80BNK, "z80->68k w8 [%06x] %02x", addr68k, data);\r
- if (PicoAHW & PAHW_MCD)\r
- PicoWriteM68k8(addr68k, data);\r
- else PicoWrite8(addr68k, data);\r
- return;\r
- }\r
+ elprintf(EL_ANOMALY, "z80 invalid w8 [%06x] %02x", a, data);\r
+}\r
\r
- // should not be needed\r
- if (a<0x4000) { Pico.zram[a&0x1fff]=data; return; }\r
+static void MEMH_FUNC z80_md_bank_write(unsigned int a, unsigned char data)\r
+{\r
+ extern void PicoWriteM68k8(unsigned int a, unsigned char d);\r
+ unsigned int addr68k;\r
\r
- elprintf(EL_ANOMALY, "z80 invalid w8 [%06x] %02x", a, data);\r
+ addr68k = Pico.m.z80_bank68k << 15;\r
+ addr68k += a & 0x7fff;\r
+\r
+ elprintf(EL_Z80BNK, "z80->68k w8 [%06x] %02x", addr68k, data);\r
+ if (PicoAHW & PAHW_MCD)\r
+ PicoWriteM68k8(addr68k, data);\r
+ else PicoWrite8(addr68k, data);\r
}\r
\r
-#ifndef _USE_CZ80\r
-PICO_INTERNAL unsigned short z80_read16(unsigned short a)\r
+// -----------------------------------------------------------------\r
+\r
+static unsigned char z80_md_in(unsigned short p)\r
{\r
- return (u16) ( (u16)z80_read(a) | ((u16)z80_read((u16)(a+1))<<8) );\r
+ elprintf(EL_ANOMALY, "Z80 port %04x read", p);\r
+ return 0xff;\r
}\r
\r
-PICO_INTERNAL void z80_write16(unsigned short data, unsigned short a)\r
+static void z80_md_out(unsigned short p, unsigned char d)\r
{\r
- z80_write((unsigned char) data,a);\r
- z80_write((unsigned char)(data>>8),(u16)(a+1));\r
+ elprintf(EL_ANOMALY, "Z80 port %04x write %02x", p, d);\r
}\r
+\r
+static void z80_mem_setup(void)\r
+{\r
+ z80_map_set(z80_read_map, 0x0000, 0x1fff, Pico.zram, 0);\r
+ z80_map_set(z80_read_map, 0x2000, 0x3fff, Pico.zram, 0);\r
+ z80_map_set(z80_read_map, 0x4000, 0x5fff, ym2612_read_local_z80, 1);\r
+ z80_map_set(z80_read_map, 0x6000, 0x7fff, z80_md_vdp_read, 1);\r
+ z80_map_set(z80_read_map, 0x8000, 0xffff, z80_md_bank_read, 1);\r
+\r
+ z80_map_set(z80_write_map, 0x0000, 0x1fff, Pico.zram, 0);\r
+ z80_map_set(z80_write_map, 0x2000, 0x3fff, Pico.zram, 0);\r
+ z80_map_set(z80_write_map, 0x4000, 0x5fff, z80_md_ym2612_write, 1);\r
+ z80_map_set(z80_write_map, 0x6000, 0x7fff, z80_md_vdp_br_write, 1);\r
+ z80_map_set(z80_write_map, 0x8000, 0xffff, z80_md_bank_write, 1);\r
+\r
+#ifdef _USE_DRZ80\r
+ drZ80.z80_in = z80_md_in;\r
+ drZ80.z80_out = z80_md_out;\r
+#endif\r
+#ifdef _USE_CZ80\r
+ Cz80_Set_Fetch(&CZ80, 0x0000, 0x1fff, (UINT32)Pico.zram); // main RAM\r
+ Cz80_Set_Fetch(&CZ80, 0x2000, 0x3fff, (UINT32)Pico.zram); // mirror\r
+ Cz80_Set_INPort(&CZ80, z80_md_in);\r
+ Cz80_Set_OUTPort(&CZ80, z80_md_out);\r
#endif\r
+}\r
\r
\r
#define cycles_68k_to_z80(x) ((x)*957 >> 11)\r
\r
+#define Z80_MEM_SHIFT 13\r
+extern unsigned long z80_read_map [0x10000 >> Z80_MEM_SHIFT];\r
+extern unsigned long z80_write_map[0x10000 >> Z80_MEM_SHIFT];\r
+typedef unsigned char (z80_read_f)(unsigned short a);\r
+typedef void (z80_write_f)(unsigned int a, unsigned char data);\r
+\r
// ---------------------------------------------------------\r
\r
// main oscillator clock which controls timing\r
#define OSC_NTSC 53693100\r
-// seems to be accurate, see scans from http://www.hot.ee/tmeeco/\r
#define OSC_PAL 53203424\r
\r
struct PicoVideo\r
#define Pico_mcd ((mcd_state *)Pico.rom)\r
\r
\r
-// Area.c\r
+// area.c\r
PICO_INTERNAL void PicoAreaPackCpu(unsigned char *cpu, int is_sub);\r
PICO_INTERNAL void PicoAreaUnpackCpu(unsigned char *cpu, int is_sub);\r
extern void (*PicoLoadStateHook)(void);\r
\r
-// cd/Area.c\r
+// cd/area.c\r
PICO_INTERNAL int PicoCdSaveState(void *file);\r
PICO_INTERNAL int PicoCdLoadState(void *file);\r
\r
extern areaseek *areaSeek;\r
extern areaclose *areaClose;\r
\r
-// Cart.c\r
+// cart.c\r
extern void (*PicoCartUnloadHook)(void);\r
\r
-// Debug.c\r
+// debug.c\r
int CM_compareRun(int cyc, int is_sub);\r
\r
-// Draw.c\r
+// draw.c\r
PICO_INTERNAL void PicoFrameStart(void);\r
void PicoDrawSync(int to, int blank_last_line);\r
extern int DrawScanline;\r
#define MAX_LINE_SPRITES 29\r
extern unsigned char HighLnSpr[240][3 + MAX_LINE_SPRITES];\r
\r
-// Draw2.c\r
+// draw2.c\r
PICO_INTERNAL void PicoFrameFull();\r
\r
-// Memory.c\r
+// memory.c\r
PICO_INTERNAL void PicoInitPc(unsigned int pc);\r
PICO_INTERNAL unsigned int PicoCheckPc(unsigned int pc);\r
PICO_INTERNAL_ASM unsigned int PicoRead32(unsigned int a);\r
PICO_INTERNAL_ASM void PicoMemReset(void);\r
PICO_INTERNAL void PicoMemResetHooks(void);\r
PICO_INTERNAL int PadRead(int i);\r
-PICO_INTERNAL unsigned char z80_read(unsigned short a);\r
-#ifndef _USE_CZ80\r
-PICO_INTERNAL_ASM void z80_write(unsigned char data, unsigned short a);\r
-PICO_INTERNAL void z80_write16(unsigned short data, unsigned short a);\r
-PICO_INTERNAL unsigned short z80_read16(unsigned short a);\r
-#else\r
-PICO_INTERNAL_ASM void z80_write(unsigned int a, unsigned char data);\r
-#endif\r
PICO_INTERNAL int ym2612_write_local(unsigned int a, unsigned int d, int is_from_z80);\r
extern unsigned int (*PicoRead16Hook)(unsigned int a, int realsize);\r
extern void (*PicoWrite8Hook) (unsigned int a,unsigned int d,int realsize);\r
extern void (*PicoWrite16Hook)(unsigned int a,unsigned int d,int realsize);\r
\r
-// cd/Memory.c\r
+// cd/memory.c\r
PICO_INTERNAL void PicoMemSetupCD(void);\r
PICO_INTERNAL_ASM void PicoMemResetCD(int r3);\r
PICO_INTERNAL_ASM void PicoMemResetCDdecode(int r3);\r
\r
-// Pico/Memory.c\r
+// pico/memory.c\r
PICO_INTERNAL void PicoMemSetupPico(void);\r
PICO_INTERNAL unsigned int ym2612_read_local_68k(void);\r
\r
-// Pico.c\r
+// pico.c\r
extern struct Pico Pico;\r
extern struct PicoSRAM SRam;\r
extern int PicoPadInt[2];\r
PICO_INTERNAL void PicoDetectRegion(void);\r
PICO_INTERNAL void PicoSyncZ80(int m68k_cycles_done);\r
\r
-// cd/Pico.c\r
+// cd/pico.c\r
PICO_INTERNAL void PicoInitMCD(void);\r
PICO_INTERNAL void PicoExitMCD(void);\r
PICO_INTERNAL void PicoPowerMCD(void);\r
PICO_INTERNAL int PicoResetMCD(void);\r
PICO_INTERNAL void PicoFrameMCD(void);\r
\r
-// Pico/Pico.c\r
+// pico/pico.c\r
PICO_INTERNAL void PicoInitPico(void);\r
PICO_INTERNAL void PicoReratePico(void);\r
\r
-// Pico/xpcm.c\r
+// pico/xpcm.c\r
PICO_INTERNAL void PicoPicoPCMUpdate(short *buffer, int length, int stereo);\r
PICO_INTERNAL void PicoPicoPCMReset(void);\r
PICO_INTERNAL void PicoPicoPCMRerate(int xpcm_rate);\r
\r
-// Sek.c\r
+// sek.c\r
PICO_INTERNAL void SekInit(void);\r
PICO_INTERNAL int SekReset(void);\r
PICO_INTERNAL void SekState(int *data);\r
void SekInitIdleDet(void);\r
void SekFinishIdleDet(void);\r
\r
-// cd/Sek.c\r
+// cd/sek.c\r
PICO_INTERNAL void SekInitS68k(void);\r
PICO_INTERNAL int SekResetS68k(void);\r
PICO_INTERNAL int SekInterruptS68k(int irq);\r
timer_b_step = TIMER_B_TICK_ZCYCLES * 256;\r
\r
\r
-// VideoPort.c\r
+// videoport.c\r
PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d);\r
PICO_INTERNAL_ASM unsigned int PicoVideoRead(unsigned int a);\r
PICO_INTERNAL_ASM unsigned int PicoVideoRead8(unsigned int a);\r
extern int (*PicoDmaHook)(unsigned int source, int len, unsigned short **srcp, unsigned short **limitp);\r
\r
-// Misc.c\r
+// misc.c\r
PICO_INTERNAL void SRAMWriteEEPROM(unsigned int d);\r
PICO_INTERNAL void SRAMUpdPending(unsigned int a, unsigned int d);\r
PICO_INTERNAL_ASM unsigned int SRAMReadEEPROM(void);\r
PICO_INTERNAL_ASM void memcpy32(int *dest, int *src, int count); // 32bit word count\r
PICO_INTERNAL_ASM void memset32(int *dest, int c, int count);\r
\r
-// cd/Misc.c\r
+// z80 functionality wrappers\r
+PICO_INTERNAL void z80_init(void);\r
+PICO_INTERNAL void z80_pack(unsigned char *data);\r
+PICO_INTERNAL void z80_unpack(unsigned char *data);\r
+PICO_INTERNAL void z80_reset(void);\r
+PICO_INTERNAL void z80_exit(void);\r
+void z80_map_set(unsigned long *map, int start_addr,\r
+ int end_addr, void *func_or_mh, int is_func);\r
+\r
+// cd/misc.c\r
PICO_INTERNAL_ASM void wram_2M_to_1M(unsigned char *m);\r
PICO_INTERNAL_ASM void wram_1M_to_2M(unsigned char *m);\r
\r
PICO_INTERNAL void PsndDoDAC(int line_to);\r
PICO_INTERNAL void PsndClear(void);\r
PICO_INTERNAL void PsndGetSamples(int y);\r
-// z80 functionality wrappers\r
-PICO_INTERNAL void z80_init(void);\r
-PICO_INTERNAL void z80_pack(unsigned char *data);\r
-PICO_INTERNAL void z80_unpack(unsigned char *data);\r
-PICO_INTERNAL void z80_reset(void);\r
-PICO_INTERNAL void z80_exit(void);\r
extern int PsndDacLine;\r
\r
// emulation event logging\r
#define cdprintf(x...)\r
#endif\r
\r
+#if defined(__GNUC__) && !defined(ARM)\r
+#define MEMH_FUNC __attribute__((aligned(4)))\r
+#else\r
+#define MEMH_FUNC\r
+#endif\r
+\r
#ifdef __cplusplus\r
} // End of extern "C"\r
#endif\r
#endif\r
}\r
\r
-\r
-// -----------------------------------------------------------------\r
-// z80 stuff\r
-\r
-#ifdef _USE_MZ80\r
-\r
-// memhandlers for mz80 core\r
-unsigned char mz80_read(UINT32 a, struct MemoryReadByte *w) { return z80_read(a); }\r
-void mz80_write(UINT32 a, UINT8 d, struct MemoryWriteByte *w) { z80_write(d, a); }\r
-\r
-// structures for mz80 core\r
-static struct MemoryReadByte mz80_mem_read[]=\r
-{\r
- {0x0000,0xffff,mz80_read},\r
- {(UINT32) -1,(UINT32) -1,NULL}\r
-};\r
-static struct MemoryWriteByte mz80_mem_write[]=\r
-{\r
- {0x0000,0xffff,mz80_write},\r
- {(UINT32) -1,(UINT32) -1,NULL}\r
-};\r
-static struct z80PortRead mz80_io_read[] ={\r
- {(UINT16) -1,(UINT16) -1,NULL}\r
-};\r
-static struct z80PortWrite mz80_io_write[]={\r
- {(UINT16) -1,(UINT16) -1,NULL}\r
-};\r
-\r
-int mz80_run(int cycles)\r
-{\r
- int ticks_pre = mz80GetElapsedTicks(0);\r
- mz80exec(cycles);\r
- return mz80GetElapsedTicks(0) - ticks_pre;\r
-}\r
-\r
-#endif\r
-\r
-#ifdef _USE_DRZ80\r
-\r
-struct DrZ80 drZ80;\r
-\r
-static unsigned int DrZ80_rebasePC(unsigned short a)\r
-{\r
- drZ80.Z80PC_BASE = (unsigned int) Pico.zram;\r
- return drZ80.Z80PC_BASE + a;\r
-}\r
-\r
-static unsigned int DrZ80_rebaseSP(unsigned short a)\r
-{\r
- drZ80.Z80SP_BASE = (unsigned int) Pico.zram;\r
- return drZ80.Z80SP_BASE + a;\r
-}\r
-#endif\r
-\r
-#if defined(_USE_DRZ80) || defined(_USE_CZ80)\r
-static unsigned char z80_in(unsigned short p)\r
-{\r
- elprintf(EL_ANOMALY, "Z80 port %04x read", p);\r
- return 0xff;\r
-}\r
-\r
-static void z80_out(unsigned short p,unsigned char d)\r
-{\r
- elprintf(EL_ANOMALY, "Z80 port %04x write %02x", p, d);\r
-}\r
-#endif\r
-\r
-\r
-// z80 functionality wrappers\r
-PICO_INTERNAL void z80_init(void)\r
-{\r
-#ifdef _USE_MZ80\r
- struct mz80context z80;\r
-\r
- // z80\r
- mz80init();\r
- // Modify the default context\r
- mz80GetContext(&z80);\r
-\r
- // point mz80 stuff\r
- z80.z80Base=Pico.zram;\r
- z80.z80MemRead=mz80_mem_read;\r
- z80.z80MemWrite=mz80_mem_write;\r
- z80.z80IoRead=mz80_io_read;\r
- z80.z80IoWrite=mz80_io_write;\r
-\r
- mz80SetContext(&z80);\r
-#endif\r
-#ifdef _USE_DRZ80\r
- memset(&drZ80, 0, sizeof(struct DrZ80));\r
- drZ80.z80_rebasePC=DrZ80_rebasePC;\r
- drZ80.z80_rebaseSP=DrZ80_rebaseSP;\r
- drZ80.z80_read8 =z80_read;\r
- drZ80.z80_read16 =NULL;\r
- drZ80.z80_write8 =z80_write;\r
- drZ80.z80_write16 =NULL;\r
- drZ80.z80_in =z80_in;\r
- drZ80.z80_out =z80_out;\r
- drZ80.z80_irq_callback=NULL;\r
-#endif\r
-#ifdef _USE_CZ80\r
- memset(&CZ80, 0, sizeof(CZ80));\r
- Cz80_Init(&CZ80);\r
- Cz80_Set_Fetch(&CZ80, 0x0000, 0x1fff, (UINT32)Pico.zram); // main RAM\r
- Cz80_Set_Fetch(&CZ80, 0x2000, 0x3fff, (UINT32)Pico.zram); // mirror\r
- Cz80_Set_ReadB(&CZ80, (UINT8 (*)(UINT32 address))z80_read); // unused (hacked in)\r
- Cz80_Set_WriteB(&CZ80, z80_write);\r
- Cz80_Set_INPort(&CZ80, z80_in);\r
- Cz80_Set_OUTPort(&CZ80, z80_out);\r
-#endif\r
-}\r
-\r
-PICO_INTERNAL void z80_reset(void)\r
-{\r
-#ifdef _USE_MZ80\r
- mz80reset();\r
-#endif\r
-#ifdef _USE_DRZ80\r
- memset(&drZ80, 0, 0x54);\r
- drZ80.Z80F = (1<<2); // set ZFlag\r
- drZ80.Z80F2 = (1<<2); // set ZFlag\r
- drZ80.Z80IX = 0xFFFF << 16;\r
- drZ80.Z80IY = 0xFFFF << 16;\r
- drZ80.Z80IM = 0; // 1?\r
- drZ80.z80irqvector = 0xff0000; // RST 38h\r
- drZ80.Z80PC = drZ80.z80_rebasePC(0);\r
- drZ80.Z80SP = drZ80.z80_rebaseSP(0x2000); // 0xf000 ?\r
-#endif\r
-#ifdef _USE_CZ80\r
- Cz80_Reset(&CZ80);\r
- Cz80_Set_Reg(&CZ80, CZ80_IX, 0xffff);\r
- Cz80_Set_Reg(&CZ80, CZ80_IY, 0xffff);\r
- Cz80_Set_Reg(&CZ80, CZ80_SP, 0x2000);\r
-#endif\r
- Pico.m.z80_fakeval = 0; // for faking when Z80 is disabled\r
-}\r
-\r
-#if 0\r
-static int had_irq = 0, z80_ppc, z80_ops_done = 0;\r
-int z80_cycles_left = 0;\r
-\r
-void z80_int(void)\r
-{\r
- had_irq = 1;\r
-}\r
-\r
-static void xfail(void)\r
-{\r
- printf("PC: %04x, %04x\n", Cz80_Get_Reg(&CZ80, CZ80_PC), z80_ppc);\r
- printf("z80_ops_done done: %i\n", z80_ops_done);\r
- exit(1);\r
-}\r
-\r
-int z80_run(int cycles)\r
-{\r
- int fail = 0;\r
- int cdrz, ccz;\r
-\r
- z80_cycles_left = cycles;\r
- z80_ppc = Cz80_Get_Reg(&CZ80, CZ80_PC);\r
-\r
- if (had_irq) {\r
- printf("irq @ %04x\n", Cz80_Get_Reg(&CZ80, CZ80_PC));\r
- Cz80_Set_IRQ(&CZ80, 0, HOLD_LINE);\r
- drZ80.Z80_IRQ = 1;\r
- had_irq = 0;\r
- }\r
-\r
- while (z80_cycles_left > 0)\r
- {\r
- ccz = Cz80_Exec(&CZ80, 1);\r
- cdrz = 1 - DrZ80Run(&drZ80, 1);\r
-\r
- if (drZ80.Z80_IRQ && (drZ80.Z80IF&1))\r
- cdrz += 1 - DrZ80Run(&drZ80, 1); // cz80 processes IRQ after EI, DrZ80 does not\r
-\r
- if (cdrz != ccz) {\r
- printf("cycles: %i vs %i\n", cdrz, ccz);\r
- fail = 1;\r
- }\r
-\r
- if (drZ80.Z80PC - drZ80.Z80PC_BASE != Cz80_Get_Reg(&CZ80, CZ80_PC)) {\r
- printf("PC: %04x vs %04x\n", drZ80.Z80PC - drZ80.Z80PC_BASE, Cz80_Get_Reg(&CZ80, CZ80_PC));\r
- fail = 1;\r
- }\r
-\r
- if (fail) xfail();\r
-\r
- z80_ops_done++;\r
- z80_cycles_left -= ccz;\r
- z80_ppc = Cz80_Get_Reg(&CZ80, CZ80_PC);\r
- }\r
-\r
- return co - z80_cycles_left;\r
-}\r
-#endif\r
-\r
-\r
-PICO_INTERNAL void z80_pack(unsigned char *data)\r
-{\r
-#if defined(_USE_MZ80)\r
- struct mz80context mz80;\r
- *(int *)data = 0x00005A6D; // "mZ"\r
- mz80GetContext(&mz80);\r
- memcpy(data+4, &mz80.z80clockticks, sizeof(mz80)-5*4); // don't save base&memhandlers\r
-#elif defined(_USE_DRZ80)\r
- *(int *)data = 0x015A7244; // "DrZ" v1\r
- drZ80.Z80PC = drZ80.z80_rebasePC(drZ80.Z80PC-drZ80.Z80PC_BASE);\r
- drZ80.Z80SP = drZ80.z80_rebaseSP(drZ80.Z80SP-drZ80.Z80SP_BASE);\r
- memcpy(data+4, &drZ80, 0x54);\r
-#elif defined(_USE_CZ80)\r
- *(int *)data = 0x00007a43; // "Cz"\r
- *(int *)(data+4) = Cz80_Get_Reg(&CZ80, CZ80_PC);\r
- memcpy(data+8, &CZ80, (INT32)&CZ80.BasePC - (INT32)&CZ80);\r
-#endif\r
-}\r
-\r
-PICO_INTERNAL void z80_unpack(unsigned char *data)\r
-{\r
-#if defined(_USE_MZ80)\r
- if (*(int *)data == 0x00005A6D) { // "mZ" save?\r
- struct mz80context mz80;\r
- mz80GetContext(&mz80);\r
- memcpy(&mz80.z80clockticks, data+4, sizeof(mz80)-5*4);\r
- mz80SetContext(&mz80);\r
- } else {\r
- z80_reset();\r
- z80_int();\r
- }\r
-#elif defined(_USE_DRZ80)\r
- if (*(int *)data == 0x015A7244) { // "DrZ" v1 save?\r
- memcpy(&drZ80, data+4, 0x54);\r
- // update bases\r
- drZ80.Z80PC = drZ80.z80_rebasePC(drZ80.Z80PC-drZ80.Z80PC_BASE);\r
- drZ80.Z80SP = drZ80.z80_rebaseSP(drZ80.Z80SP-drZ80.Z80SP_BASE);\r
- } else {\r
- z80_reset();\r
- drZ80.Z80IM = 1;\r
- z80_int(); // try to goto int handler, maybe we won't execute trash there?\r
- }\r
-#elif defined(_USE_CZ80)\r
- if (*(int *)data == 0x00007a43) { // "Cz" save?\r
- memcpy(&CZ80, data+8, (INT32)&CZ80.BasePC - (INT32)&CZ80);\r
- Cz80_Set_Reg(&CZ80, CZ80_PC, *(int *)(data+4));\r
- } else {\r
- z80_reset();\r
- z80_int();\r
- }\r
-#endif\r
-}\r
-\r
-PICO_INTERNAL void z80_exit(void)\r
-{\r
-#if defined(_USE_MZ80)\r
- mz80shutdown();\r
-#endif\r
-}\r
-\r
-#if 1 // defined(__DEBUG_PRINT) || defined(__GP2X__) || defined(__GIZ__)\r
-PICO_INTERNAL void z80_debug(char *dstr)\r
-{\r
-#if defined(_USE_DRZ80)\r
- sprintf(dstr, "Z80 state: PC: %04x SP: %04x\n", drZ80.Z80PC-drZ80.Z80PC_BASE, drZ80.Z80SP-drZ80.Z80SP_BASE);\r
-#elif defined(_USE_CZ80)\r
- sprintf(dstr, "Z80 state: PC: %04x SP: %04x\n", CZ80.PC - CZ80.BasePC, CZ80.SP.W);\r
-#endif\r
-}\r
-#endif\r
--- /dev/null
+#include "pico_int.h"
+#include "sound/sn76496.h"
+
+#define Z80_MEM_SHIFT 13
+
+unsigned long z80_read_map [0x10000 >> Z80_MEM_SHIFT];
+unsigned long z80_write_map[0x10000 >> Z80_MEM_SHIFT];
+
+void MEMH_FUNC z80_map_set(unsigned long *map, int start_addr, int end_addr,
+ void *func_or_mh, int is_func)
+{
+ unsigned long addr = (unsigned long)func_or_mh;
+ int mask = (1 << Z80_MEM_SHIFT) - 1;
+ int i;
+
+ if ((start_addr & mask) != 0 || (end_addr & mask) != mask)
+ elprintf(EL_STATUS|EL_ANOMALY, "z80_map_set: tried to map bad range: %04x-%04x",
+ start_addr, end_addr);
+
+ if (addr & 1) {
+ elprintf(EL_STATUS|EL_ANOMALY, "z80_map_set: ptr is not aligned: %08lx", addr);
+ return;
+ }
+
+ for (i = start_addr >> Z80_MEM_SHIFT; i <= end_addr >> Z80_MEM_SHIFT; i++)
+ if (is_func)
+ map[i] = (addr >> 1) | (1 << (sizeof(addr) * 8 - 1));
+ else
+ map[i] = (addr - (i << Z80_MEM_SHIFT)) >> 1;
+}
+
+#ifdef _USE_MZ80
+
+// memhandlers for mz80 core
+unsigned char mz80_read(UINT32 a, struct MemoryReadByte *w) { return z80_read(a); }
+void mz80_write(UINT32 a, UINT8 d, struct MemoryWriteByte *w) { z80_write(d, a); }
+
+// structures for mz80 core
+static struct MemoryReadByte mz80_mem_read[]=
+{
+ {0x0000,0xffff,mz80_read},
+ {(UINT32) -1,(UINT32) -1,NULL}
+};
+static struct MemoryWriteByte mz80_mem_write[]=
+{
+ {0x0000,0xffff,mz80_write},
+ {(UINT32) -1,(UINT32) -1,NULL}
+};
+static struct z80PortRead mz80_io_read[] ={
+ {(UINT16) -1,(UINT16) -1,NULL}
+};
+static struct z80PortWrite mz80_io_write[]={
+ {(UINT16) -1,(UINT16) -1,NULL}
+};
+
+int mz80_run(int cycles)
+{
+ int ticks_pre = mz80GetElapsedTicks(0);
+ mz80exec(cycles);
+ return mz80GetElapsedTicks(0) - ticks_pre;
+}
+
+#endif
+
+#ifdef _USE_DRZ80
+
+struct DrZ80 drZ80;
+
+static unsigned int DrZ80_rebasePC(unsigned short a)
+{
+ drZ80.Z80PC_BASE = (unsigned int) Pico.zram;
+ return drZ80.Z80PC_BASE + a;
+}
+
+static unsigned int DrZ80_rebaseSP(unsigned short a)
+{
+ drZ80.Z80SP_BASE = (unsigned int) Pico.zram;
+ return drZ80.Z80SP_BASE + a;
+}
+#endif
+
+
+PICO_INTERNAL void z80_init(void)
+{
+#ifdef _USE_MZ80
+ struct mz80context z80;
+
+ // z80
+ mz80init();
+ // Modify the default context
+ mz80GetContext(&z80);
+
+ // point mz80 stuff
+ z80.z80Base=Pico.zram;
+ z80.z80MemRead=mz80_mem_read;
+ z80.z80MemWrite=mz80_mem_write;
+ z80.z80IoRead=mz80_io_read;
+ z80.z80IoWrite=mz80_io_write;
+
+ mz80SetContext(&z80);
+#endif
+#ifdef _USE_DRZ80
+ memset(&drZ80, 0, sizeof(drZ80));
+ drZ80.z80_rebasePC=DrZ80_rebasePC;
+ drZ80.z80_rebaseSP=DrZ80_rebaseSP;
+ drZ80.z80_read8 =(void *)z80_read_map;
+ drZ80.z80_read16 =NULL;
+ drZ80.z80_write8 =(void *)z80_write_map;
+ drZ80.z80_write16 =NULL;
+ drZ80.z80_irq_callback=NULL;
+#endif
+#ifdef _USE_CZ80
+ memset(&CZ80, 0, sizeof(CZ80));
+ Cz80_Init(&CZ80);
+ Cz80_Set_ReadB(&CZ80, NULL); // unused (hacked in)
+ Cz80_Set_WriteB(&CZ80, NULL);
+#endif
+}
+
+PICO_INTERNAL void z80_reset(void)
+{
+#ifdef _USE_MZ80
+ mz80reset();
+#endif
+#ifdef _USE_DRZ80
+ memset(&drZ80, 0, 0x54);
+ drZ80.Z80F = (1<<2); // set ZFlag
+ drZ80.Z80F2 = (1<<2); // set ZFlag
+ drZ80.Z80IX = 0xFFFF << 16;
+ drZ80.Z80IY = 0xFFFF << 16;
+ drZ80.Z80IM = 0; // 1?
+ drZ80.z80irqvector = 0xff0000; // RST 38h
+ drZ80.Z80PC = drZ80.z80_rebasePC(0);
+ drZ80.Z80SP = drZ80.z80_rebaseSP(0x2000); // 0xf000 ?
+#endif
+#ifdef _USE_CZ80
+ Cz80_Reset(&CZ80);
+ Cz80_Set_Reg(&CZ80, CZ80_IX, 0xffff);
+ Cz80_Set_Reg(&CZ80, CZ80_IY, 0xffff);
+ Cz80_Set_Reg(&CZ80, CZ80_SP, 0x2000);
+#endif
+ Pico.m.z80_fakeval = 0; // for faking when Z80 is disabled
+}
+
+PICO_INTERNAL void z80_pack(unsigned char *data)
+{
+#if defined(_USE_MZ80)
+ struct mz80context mz80;
+ *(int *)data = 0x00005A6D; // "mZ"
+ mz80GetContext(&mz80);
+ memcpy(data+4, &mz80.z80clockticks, sizeof(mz80)-5*4); // don't save base&memhandlers
+#elif defined(_USE_DRZ80)
+ *(int *)data = 0x015A7244; // "DrZ" v1
+ drZ80.Z80PC = drZ80.z80_rebasePC(drZ80.Z80PC-drZ80.Z80PC_BASE);
+ drZ80.Z80SP = drZ80.z80_rebaseSP(drZ80.Z80SP-drZ80.Z80SP_BASE);
+ memcpy(data+4, &drZ80, 0x54);
+#elif defined(_USE_CZ80)
+ *(int *)data = 0x00007a43; // "Cz"
+ *(int *)(data+4) = Cz80_Get_Reg(&CZ80, CZ80_PC);
+ memcpy(data+8, &CZ80, (INT32)&CZ80.BasePC - (INT32)&CZ80);
+#endif
+}
+
+PICO_INTERNAL void z80_unpack(unsigned char *data)
+{
+#if defined(_USE_MZ80)
+ if (*(int *)data == 0x00005A6D) { // "mZ" save?
+ struct mz80context mz80;
+ mz80GetContext(&mz80);
+ memcpy(&mz80.z80clockticks, data+4, sizeof(mz80)-5*4);
+ mz80SetContext(&mz80);
+ } else {
+ z80_reset();
+ z80_int();
+ }
+#elif defined(_USE_DRZ80)
+ if (*(int *)data == 0x015A7244) { // "DrZ" v1 save?
+ memcpy(&drZ80, data+4, 0x54);
+ // update bases
+ drZ80.Z80PC = drZ80.z80_rebasePC(drZ80.Z80PC-drZ80.Z80PC_BASE);
+ drZ80.Z80SP = drZ80.z80_rebaseSP(drZ80.Z80SP-drZ80.Z80SP_BASE);
+ } else {
+ z80_reset();
+ drZ80.Z80IM = 1;
+ z80_int(); // try to goto int handler, maybe we won't execute trash there?
+ }
+#elif defined(_USE_CZ80)
+ if (*(int *)data == 0x00007a43) { // "Cz" save?
+ memcpy(&CZ80, data+8, (INT32)&CZ80.BasePC - (INT32)&CZ80);
+ Cz80_Set_Reg(&CZ80, CZ80_PC, *(int *)(data+4));
+ } else {
+ z80_reset();
+ z80_int();
+ }
+#endif
+}
+
+PICO_INTERNAL void z80_exit(void)
+{
+#if defined(_USE_MZ80)
+ mz80shutdown();
+#endif
+}
+
+PICO_INTERNAL void z80_debug(char *dstr)
+{
+#if defined(_USE_DRZ80)
+ sprintf(dstr, "Z80 state: PC: %04x SP: %04x\n", drZ80.Z80PC-drZ80.Z80PC_BASE, drZ80.Z80SP-drZ80.Z80SP_BASE);
+#elif defined(_USE_CZ80)
+ sprintf(dstr, "Z80 state: PC: %04x SP: %04x\n", CZ80.PC - CZ80.BasePC, CZ80.SP.W);
+#endif
+}
OBJS += picoAll.o\r
else\r
OBJS += pico/area.o pico/cart.o pico/memory.o pico/misc.o pico/pico.o pico/sek.o \\r
- pico/videoport.o pico/draw2.o pico/draw.o pico/patch.o pico/debug.o\r
+ pico/videoport.o pico/draw2.o pico/draw.o pico/z80if.o pico/patch.o pico/debug.o\r
# Pico - CD\r
OBJS += pico/cd/pico.o pico/cd/memory.o pico/cd/sek.o pico/cd/LC89510.o \\r
pico/cd/cd_sys.o pico/cd/cd_file.o pico/cd/gfx_cd.o pico/cd/cue.o \\r
ifeq "$(amalgamate)" "1"\r
OBJS += ../../picoAll.o\r
else\r
-OBJS += pico/area.o pico/cart.o pico/memory.o pico/misc.o pico/pico.o pico/sek.o \\r
+OBJS += pico/area.o pico/cart.o pico/memory.o pico/misc.o pico/pico.o pico/sek.o pico/z80if.o \\r
pico/videoport.o pico/draw2.o pico/draw.o pico/patch.o pico/debug.o\r
# Pico - CD\r
OBJS += pico/cd/pico.o pico/cd/memory.o pico/cd/sek.o pico/cd/LC89510.o \\r
# Pico
OBJS += pico/area.o pico/cart.o pico/memory.o pico/misc.o pico/pico.o pico/sek.o \
- pico/videoport.o pico/draw2.o pico/draw.o pico/patch.o pico/debug.o
+ pico/videoport.o pico/draw2.o pico/draw.o pico/z80if.o pico/patch.o pico/debug.o
# Pico - CD
OBJS += pico/cd/pico.o pico/cd/memory.o pico/cd/sek.o pico/cd/LC89510.o \
pico/cd/cd_sys.o pico/cd/cd_file.o pico/cd/cue.o pico/cd/gfx_cd.o \
OBJS += ../../picoAll.o\r
else\r
OBJS += pico/area.o pico/cart.o pico/memory.o pico/misc.o pico/pico.o pico/sek.o pico/videoport.o \\r
- pico/draw2.o pico/draw.o pico/patch.o pico/draw_amips.o pico/memory_amips.o \\r
- pico/misc_amips.o pico/debug.o\r
+ pico/draw2.o pico/draw.o pico/z80if.o pico/patch.o pico/draw_amips.o pico/memory_amips.o \\r
+ pico/misc_amips.o pico/debug.o\r
# Pico - CD\r
OBJS += pico/cd/pico.o pico/cd/memory.o pico/cd/sek.o pico/cd/LC89510.o \\r
pico/cd/cd_sys.o pico/cd/cd_file.o pico/cd/cue.o pico/cd/gfx_cd.o \\r